{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import json\n",
    "import exifread\n",
    "import subprocess\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "from PIL import Image\n",
    "\n",
    "import env\n",
    "from utils import KaggleCameraDataset, progress_iter, RNG\n",
    "\n",
    "%matplotlib inline\n",
    "%load_ext autoreload\n",
    "%autoreload 2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## validation set"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "N_VAL_PER_CLASS = 48\n",
    "val, no_val = [], []"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### get best images from Gleb's val set (quality $\\geq$ 95)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "with open('../data/glebs_val_stats.json') as f:\n",
    "    glebs_val_stats = json.load(f)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "325 9\n"
     ]
    }
   ],
   "source": [
    "gv_yes, gv_no = [], []\n",
    "for i, d in sorted(glebs_val_stats.items()):\n",
    "    if d['quality'] and d['quality'] >= 95:\n",
    "        gv_yes.append((d['x_fpath'], d['y']))\n",
    "    else:\n",
    "        gv_no.append((d['x_fpath'], d['y'], d['quality'], d['res'], d['res_valid']))\n",
    "print len(gv_yes), len(gv_no)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "val += gv_yes\n",
    "no_val += gv_no"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[45, 37, 14, 28, 30, 18, 44, 42, 36, 31]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAEACAYAAACj0I2EAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAESZJREFUeJzt3W+sZHV9x/H3Z0EpilAKuituhNhGxCYUSRSVNF4KrYip\nYhMSxFZE02gqSsRakAfu0vJAHoA1ER9YKF2MohUlYGL413Uw2PinhQ0giE0Vkdq91gi2hIAg3z6Y\ns+G63GVm7szcc/d336/kZM+cc+b8vnsy9zNnfudfqgpJ0t5vQ98FSJJmw0CXpEYY6JLUCANdkhph\noEtSIwx0SWrE2IGeZEOSO5Jc373+pyQ/7KbdnuTo+ZUpSRpl3wmWPQf4HnBg97qAD1fVtTOvSpI0\nsbH20JNsBk4BLl/J+yVJ8zduIH8C+AjDvfKlLkqyI8klSZ4z29IkSZMYGehJ3gwsVtUOIEtmnV9V\nRwGvBg4BzptPiZKkcYzTh3488JYkpwD7Ay9IclVVvROgqp5IciXw4eXenMSbxUjSClRVRi/1tJF7\n6FV1QVW9tKpeBpwObK+qdybZBJAkwKnA3c+yllUePsVZZ/0VVbWmhi1btvRew1oZ3BZuC7fFsw8r\nMclZLrv7XJJDGXbD7ADeN8W6JElTmijQq+pW4NZu/MS5VCRJWhFPO1xFCwsLfZewZrgtnua2eJrb\nYjrTdLloQn5Yn7Y3b4tNm45gcfHHq97uxo2Hs3Pn/ave7mramz8Xa4GBLk1oGOarf/LW4uJEJzxo\nHbLLRZIaYaBLUiMMdElqhIEuSY0w0CWpEQa6JDXCQJekRngeurTX2I/hvfBW13q4oKkVBrq013gc\nL2jSs7HLRZIaYaBLUiMMdElqhIEuSY0YO9CTbEhye5Lru9dHJPlWkvuSXJ3EA6yS1KNJ9tDPAe5Z\n8vpi4JKqOhJ4GHjPLAuTJE1mrEBPshk4Bbh8yeQ/Ar7cjW8D3jbb0iRJkxh3D/0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1V1FPAHwLrsskxyGPAB4NiqOpphV/Dp/Va16q5kmJdLnQ/cUlVH\nAtuBj45aybz20L3oqFNVO6tqRzf+CMM/2nV7vn6SzcApwOV919KnJC8A/rCqrgSoqier6n97LqtP\n+wDPT7Iv8Dzgpz3Xs6qq6jbgod0mvxXY1o1vA04dtZ55BboXHS0jyRHAMcC3+62kV58APsIerllY\nR14G/DzJlV3302eS7N93UX2oqp8ClwAPAP8FPFxVt/Rb1ZrwoqpahOGOIfDCUW+YV6CPfdHRepHk\nAOAa4JxuT33dSfJmYLH7xRKW/5ysF/sCxwKXVdWxwKMMf2KvO0l+m+He6OHAYcABSc7ot6q907wC\n/UHgpUteb2ad/YRaqvsZeQ3w2aq6ru96enQ88JYkPwSuBk5IclXPNfXlQeAnVfVv3etrGAb8enQS\n8MOq+kVV/Rr4CvD6nmtaCxaTbARIsgn42ag3zCvQvwv8XpLDu6PVpwPr+YyGfwTuqapP9l1In6rq\ngqp6aVW9jOFnYntVvbPvuvrQ/ZT+SZKXd5NOZP0eKH4AeG2S30oShttiPR4g3v1X6/XAu7rxM4GR\nO4PT3Mtlj7zo6GlJjgfeAdyV5A6GXU8XVNUN/VamNeCDwOeSPAf4IXBWz/X0oqq+k+Qa4A7gie7f\nz/Rb1epK8nlgATgkyQPAFuDjwJeSvJvhl95pI9fjhUWS1AYfQSdJjTDQJakRBrokNcJAl6RGGOiS\n1AgDXZIaYaBLUiMMdElqxP8D1WoYiAsidfEAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f8cb0044510>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "VAL_CLASSES = map(int, plt.hist(zip(*val)[1])[0])\n",
    "VAL_CLASSES"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### get best images from alex firsov val set (quality $\\geq$ 95)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "with open('../data/alex_firsov_stats.json') as f:\n",
    "    alex_firsov_stats = json.load(f)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "333 11\n"
     ]
    }
   ],
   "source": [
    "af_yes, af_no = [], []\n",
    "for i, d in sorted(alex_firsov_stats.items()):\n",
    "    d['y'] = 4  # !!!!!!!!!!!!\n",
    "    d['x_fpath'] = d['x_fpath'].replace('Motorola-Droid-Maxx', 'Motorola-X')\n",
    "    if d['quality'] and d['quality'] >= 95:\n",
    "        af_yes.append((d['x_fpath'], d['y'], d['quality'], d['res'], d['res_valid']))\n",
    "    else:\n",
    "        af_no.append((d['x_fpath'], d['y'], d['quality'], d['res'], d['res_valid']))\n",
    "print len(af_yes), len(af_no)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "RNG(seed=1337).shuffle(af_yes)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "val += map(lambda (x,y,q,r,rv): (x,y), af_yes[:(N_VAL_PER_CLASS - VAL_CLASSES[4])])\n",
    "no_val += af_no\n",
    "no_val += af_yes[(N_VAL_PER_CLASS - VAL_CLASSES[4]):]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[45, 37, 14, 28, 48, 18, 44, 42, 36, 31]"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAEACAYAAACj0I2EAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAADitJREFUeJzt3W+sJXV9x/H3Z7ktoChSi7ulG9gQ4oJNLPIAUNLkUmm1\nmgo+oE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Z7rmZqq+j7w\nwkGLzwd2dPM7gAuG2dekAt2bjpaRZAtwOvCDfivp1ReBbRzinoUZcjLwXJJbu+GnLyc5uu+i+lBV\nzwA3AU8C/wO8WFX39VtV795TVQuw2CkEjh9mo0kF+tA3Hc2KJMcAdwJXdD31mZPk48BC94klLP97\nMivmgDOAv6mqM4Cfs/gxe+YkeReLPdKTgBOAY5J8ut+qDk+TCvSngROXvN7MDH2EOlj3MfJO4GtV\ndXff9fToHOATSR4FbgfOTfLVnmvqy9PAU1X14+71nSwG/Cw6D3i0qp6vql8C3wE+1HNNfVtIshEg\nySbg2WE2mlSg/wg4JclJ3dnqi4BZvqLhFuDhqvpS34X0qaqurqoTq+pkFn8ndlXVn/RdVx+6j9NP\nJXlvt+jDzO6J4ieBs5MclSQsHotZO0F88CfWe4BLuvmLgaE6gmv5LpdD8qajNyQ5B/gMsCfJbhaH\nnq6uqn/qtzKtA5cDtyX5FeBR4LM919OLqvphkjuB3cCr3b9f7req6UnydWAeeHeSJ4FrgOuBbyW5\nlMU/eBcOtS9vLJKkNvgIOklqhIEuSY0w0CWpEQa6JDXCQJekRhjoktQIA12SGmGgS1Ij/h+ClV39\nlKkv5gAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f8c4792ce50>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "VAL_CLASSES = map(int, plt.hist(zip(*val)[1])[0])\n",
    "VAL_CLASSES"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### fill other classes with $\\geq$ 95 from esato"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "with open('../data/esato_stats.json') as f:\n",
    "    esato_stats = json.load(f)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1063 89\n"
     ]
    }
   ],
   "source": [
    "es_yes, es_no = [], []\n",
    "for i, d in sorted(esato_stats.items()):\n",
    "    if d['x_fpath'].endswith('jpg.1'):\n",
    "        continue\n",
    "    if d['quality'] and d['quality'] >= 95:\n",
    "        es_yes.append((d['x_fpath'], d['y'], d['quality'], d['res'], d['res_valid']))\n",
    "    else:\n",
    "        es_no.append((d['x_fpath'], d['y'], d['quality'], d['res'], d['res_valid']))\n",
    "print len(es_yes), len(es_no)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[2, 0, 15, 0, 362, 0, 6, 0, 546, 132]"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAEACAYAAABI5zaHAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAERNJREFUeJzt3WGMZWV9x/HvD1apCC6gsqO74BaCSI0pYIWttvVaiAok\nYtOSSkMUpJWmGKgmNosvyvZFm2BCRKIJMaUUGgoIFKEtlS1ZxsZEQAurKLBdJZQF3FELaxUTK/Dv\niznAZZnZucPOzLn7zPeT3Mw5z33OOf85e+Y3zz5z77mpKiRJbdmr7wIkSQvPcJekBhnuktQgw12S\nGmS4S1KDDHdJatBI4Z5kZZLrkzyQ5LtJjk9yYJKNSbYkuS3JyqH+lybZmmRzkqMXr3xJ0kxGHbl/\nDri1qo4Cfh14EFgP3F5VRwKbgAsAkpwEHF5VRwDnAJcteNWSpF3KXG9iSrI/sLmqDt+p/UHg3VU1\nlWQCuKOqjkpyWbd8XdfvAWBQVVOL8y1IknY2ysj9MODHSa5Ick+SLybZF1j1XGBX1Xbg4K7/amDb\n0PaPdW2SpCUySrivAI4FvlBVxwJPMT0lM9uQPzO0eY8DSVpCK0bo8yiwraq+2a3fyHS4TyVZNTQt\n88Oh/ocMbb8GeHznnSYx8CXpZaiqmQbRL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RYa7JDXIcJekBhnuktQgw12SGmS4S1KDDHdJapDhLkkN+n+M\nkOHM/lwO1QAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f8c47833290>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "map(int, plt.hist(zip(*es_yes)[1])[0])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### add all with valid resolution first"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 0, 0, 0, 0, 0, 89, 0, 0, 4]"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXUAAAEACAYAAABMEua6AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAErFJREFUeJzt3X+sZOdd3/H3Z72OsUO8rN1lV44dm6Sy66ISxyDbBZJM\nsCXiQL1OxTakSlmHpKACTQQIvKkQe/0HVY1k8UMBKkowixT8K4F4KSAbYw9RVcyP+GdiexMSJWtj\n9iYQr0OUKnLsb/+Y4+XqZvbeM3dm7o/H75c02jPnPmfO99HZ+dxnnpm5T6oKSVIbtm10AZKk2THU\nJakhhrokNcRQl6SGGOqS1BBDXZIa0ivUk7w3yaPd7T3dvp1J7k5yJMldSXbMt1RJ0mpWDfUk3wq8\nC/gO4BLg+5P8S+AAcE9VXQTcC7xvnoVKklbXZ6R+MXB/VX21qp4HPgq8FbgGONS1OQRcO58SJUl9\n9Qn1jwNv6KZbzgDeApwH7K6qRYCqOgbsml+ZkqQ+tq/WoKqeSHIjcA/wT8BDwNfmXZgkaXKrhjpA\nVd0M3AyQ5BeAJ4HFJLurajHJHuDz445N4h+XkaQ1qKpMekzfT7/s6v59FaP59FuAw8B1XZP9wJ0r\nFNbs7eDBgxteg32zf/avvdta9RqpAx9Ochbw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xiN\n5s5nNFXxjUn+4/JmY+5vievXs3+HgQuq6hLgz/jnVyWbWo3+TtaNwD3AHwMPAV9b1mzi596sQv0p\n4Mmq+pvu/ocYBeHyNkt/C53L+JdRm82qfauqL1fVV7rtPwFO3SojoSWuBj5WVV8Y87Oteu2WOmn/\ntvj1uwr4TFV9sRuF/z7wncvaPEl3/brvl5xZVc+sb5lrtmr/quqZqnquu/u/gG9f5xrXrKpurqpv\nr6oB8AzwqWVNJn7uzSTUq2oReDLJhd2uK4HHljU7DPwQnPg26vHuuE2tT9+WznEluYzRR0W/uH5V\nzsTbOfnUxJa8dsuctH9b/PodZTR19A0Z/XnBK4Hl3xf5Q0ZvJgLsA+5dx/qmtWr/kuxZcncvX589\nm1aSXd2/r2I0n778/+jkz70ZvpP7WkZ/fvchRr9NdwA/CvzIkjbvB/4WeBi4dKPffZ5V34AfZzQ/\n9iDwf4HLN7rmCft3OvAF4BVL9jVx7fr0r4Hrd5BR0D3C6JNapwI3AN/f/fw04HZGo8D7GU1VbHjd\nM+zff19y/f4MuHCja56gbx9dUvug2zfVc88vH0lSQ1zOTpIaYqhLUkMMdUlqiKEuSQ0x1CWpIYa6\nJDXEUJekhhjqktSQ/w+E919+ZJ43owAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f8c47920b90>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "map(int, plt.hist(zip(*filter(lambda (x,y,q,r,rv): rv, es_yes))[1])[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "es_yes_valid = filter(lambda (x,y,q,r,rv): rv, es_yes)\n",
    "es_yes_not_valid = filter(lambda (x,y,q,r,rv): not rv, es_yes)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAEACAYA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Q/Whqp4B7gYOA/8NvFBVe/udqndvrKoF\nGO4UAueMc6dZBX3sk47WiyRnAruAW7o99XUnyfuBhe47lrD035P1YiNwKfDXVXUp8DOG32avO0le\nz3CP9ALgPODMJB/qd6pT06yC/jRw/qLrW1hH30KdqPs2chfw+ap6sO95enQl8IdJngDuB65K8rme\nZ+rL08BTVfW97vouhoFfj64Gnqiq56rqF8BXgXf0PFPfFpJsBkhyLvDsOHeaVdC/C/xWkgu6n1Zf\nD6znVzT8HfB4Ve3se5A+VdUdVXV+VV3E8O/Evqr6477n6kP37fRTSd7UrXon6/cHxYeBK5KcniQM\nn4v19gPiE79jfQi4sVu+ARhrR3Al7+VyUp50dFySK4EPAweS7Gd46OmOqvqHfifTGnAzcF+SXwGe\nAD7a8zy9qKrvJNkF7Ade6n79TL9TrZ4kXwDmgDckOQxsB+4CvpzkJob/4V031mN5YpEktcGPoJOk\nRhh0SWqEQZekRhh0SWqEQZekRhh0SWqEQZekRhh0SWrE/wEvcCVaq8Bd/QAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f8c474fc810>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "for x,y,q,r,rv in es_yes_valid:\n",
    "    VAL_CLASSES = map(int, plt.hist(zip(*val)[1])[0])\n",
    "    if VAL_CLASSES[y] < N_VAL_PER_CLASS:\n",
    "        val.append((x, y))\n",
    "    else:\n",
    "        no_val.append((x,y,q,r,rv))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[45, 37, 14, 28, 48, 18, 45, 42, 48, 35]"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAEACAYAAACj0I2EAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAADidJREFUeJzt3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Zz2X1adjgLcnmQHeBjzbcz0TU1XfB148ZPXF\nwPZueTtwyTDHWqlAd9LRApJsBM4CftBvJb36IrCZw8xZmCKnAc8nub0bfvpykuP7LqoPVfUscAvw\nFPDfwEtV9UC/VfXuPVU1B/OdQuDkYXZaqUAfetLRtEhyAnA3cE3XU586ST4GzHWvWMLCPyfTYgY4\nG/jrqjob+DnzL7OnTpJ3Md8j3QCcApyQ5NP9VnV0WqlAfwY49aDn65mil1CH6l5G3g18raru7bue\nHp0PfCLJY8CdwAVJvtpzTX15Bni6qn7cPb+b+YCfRhcCj1XVC1X1S+A7wId6rqlvc0nWAiRZBzw3\nzE4rFeg/Ak5PsqF7t/oyYJqvaLgN2FNVX+q7kD5V1fVVdWpVncb8z8TOqvrjvuvqQ/dy+ukk7+1W\nfZjpfaP4KeC8JMclCfPnYtreID70Fet9wBXd8uXAUB3B5XyWy2E56ehNSc4HPgPsTrKL+aGn66vq\nH/utTKvA1cAdSX4FeAz4bM/19KKqfpjkbmAX8Fr375f7rWpyknwdmAXeneQp4AbgJuBbSa5k/g/e\npUMdy4lFktQGb0EnSY0w0CWpEQa6JDXCQJekRhjoktQIA12SGmGgS1IjDHRJasT/AYVtQu92XyAq\nAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f8c47313f50>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "VAL_CLASSES = map(int, plt.hist(zip(*val)[1])[0])\n",
    "VAL_CLASSES"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### now add with incorrect resolution (UPD: add incorrect resolution -> train for further filtering)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "RNG(seed=42).shuffle(es_yes_not_valid)\n",
    "for x,y,q,r,rv in es_yes_not_valid:\n",
    "    no_val.append((x,y,q,r,rv))    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[45, 37, 14, 28, 48, 18, 45, 42, 48, 35]"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAEACAYAAACj0I2EAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAADidJREFUeJzt3V2MXOV9x/Hvz2wLJCSEpsQutbCFUAyplBIugARVWhra\npEQJ5IKKJFUh0Luk0CJZMdxg1BssgdJIrVpFAepEhJCQUKgUFRc5g5RW5EUxxa2pU5X3Ui9FvEQo\nEsHh34s9BuOuvTO7s3PWz3w/0shnjs85z3/P7v72mWfOMydVhSTp6Lem7wIkSeNhoEtSIwx0SWqE\ngS5JjTDQJakRBrokNWJmmI2SPAG8DLwOvFZV5yQ5CbgL2AA8AfxhVb28QnVKkhYxbA/9dWC2qj5Q\nVed067YAD1TVJmAncN1KFChJGs6wgZ4Ftr0Y2N4tbwcuGVdRkqTRDRvoBdyf5EdJ/qRbt7aq5gCq\nah9w8koUKEkazlBj6MCHqmpfkpOBHUn2Mh/ykqRVYqhA73rgVNX/Jvl74BxgLsnaqppLsg54bqF9\nkxj8krQEVZVRtl90yCXJ25Kc0C2/Hfh9YDdwH3BFt9nlwL1HKMpHFTfccEPvNayWh+fCc+G5OPJj\nKYbpoa8F7ul62jPAHVW1I8mPgW8muRJ4Crh0SRVIksZi0UCvqseBsxZY/wJw4UoUJUkanTNFJ2h2\ndrbvElYNz8WbPBdv8lwsT5Y6VjN0A0mtdBuS1Jok1LjfFJUkHR0MdElqhIEuSY0w0LUs69ZtJMnE\nH+vWbez7S58afo+PHr4pqmVJQj+fApElT77QaPwe98M3RSVpihnoktQIA12SGmGgS1IjDHRJaoSB\nLkmNMNAlqREGuiQ1wkCXpEYY6JLUiKFuEr1cV131+Uk084YEtmz5M04//fSJtitJfZpIoN922xmT\naOYNa9b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KcmKSbyV5NMm/Jzm375r6kuTPk/xbkkeS3JHkV/uuaVKS\n3JpkLskjB607KcmOJHuT3J/kxGGOtSKB7qSjt9gPXFtV7wM+CHxuis/FAdcAe/ouYhX4EvDdqjoT\n+G1gKocsk5wC/ClwdlW9n/mh4Mv6rWqibmc+Kw+2BXigqjYBO4HrhjnQSvXQnXTUqap9VfVwt/wK\n87+0U3u9fpL1wEXAV/qupU9J3gH8TlXdDlBV+6vqZz2X1adjgLcnmQHeBjzbcz0TU1XfB148ZPXF\nwPZueTtwyTDHWqlAd9LRApJsBM4CftBvJb36IrCZw8xZmCKnAc8nub0bfvpykuP7LqoPVfUscAvw\nFPDfwEtV9UC/VfXuPVU1B/OdQuDkYXZaqUAfetLRtEhyAnA3cE3XU586ST4GzHWvWMLCPyfTYgY4\nG/jrqjob+DnzL7OnTpJ3Md8j3QCcApyQ5NP9VnV0WqlAfwY49aDn65mil1CH6l5G3g18raru7bue\nHp0PfCLJY8CdwAVJvtpzTX15Bni6qn7cPb+b+YCfRhcCj1XVC1X1S+A7wId6rqlvc0nWAiRZBzw3\nzE4rFeg/Ak5PsqF7t/oyYJqvaLgN2FNVX+q7kD5V1fVVdWpVncb8z8TOqvrjvuvqQ/dy+ukk7+1W\nfZjpfaP4KeC8JMclCfPnYtreID70Fet9wBXd8uXAUB3B5XyWy2E56ehNSc4HPgPsTrKL+aGn66vq\nH/utTKvA1cAdSX4FeAz4bM/19KKqfpjkbmAX8Fr375f7rWpyknwdmAXeneQp4AbgJuBbSa5k/g/e\npUMdy4lFktQGb0EnSY0w0CWpEQa6JDXCQJekRhjoktQIA12SGmGgS1IjDHRJasT/AYVtQu92XyAq\nAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f8c466fa610>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "VAL_CLASSES = map(int, plt.hist(zip(*val)[1])[0])\n",
    "VAL_CLASSES"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "no_val += es_no"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## training set\n",
    "### load Gleb's train and remove $\\lt$ 93"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "with open('../data/orig_stats.json') as f:\n",
    "    train_stats = json.load(f)\n",
    "for x,y,q in train_stats:\n",
    "    no_val.append((x,y,q,None,True))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "QUALITY_THRESHOLD = 93"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "with open('../data/glebs_train_stats.json') as f:\n",
    "    glebs_train_stats = json.load(f)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "9229\n"
     ]
    }
   ],
   "source": [
    "print len(filter(lambda q: q >= QUALITY_THRESHOLD, [v['quality'] for k, v in glebs_train_stats.items()]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1775\n"
     ]
    }
   ],
   "source": [
    "print len(filter(lambda q: not q or q < QUALITY_THRESHOLD, [v['quality'] for k, v in glebs_train_stats.items()]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n"
     ]
    }
   ],
   "source": [
    "print len(filter(lambda q: not q or q < QUALITY_THRESHOLD, [q for x,y,q in train_stats]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "train = []\n",
    "for x,y,q,r,rv in no_val:\n",
    "    if q >= QUALITY_THRESHOLD:\n",
    "        train.append((x,y,q,r,rv))\n",
    "for i, d in sorted(glebs_train_stats.items()):\n",
    "    if d['quality'] >= QUALITY_THRESHOLD:\n",
    "        train.append((d['x_fpath'], d['y'], d['quality'], d['res'], d['res_valid']))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### NEW: add artgor data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "with open('../data/artgor_stats.json') as f:\n",
    "    artgor_stats = json.load(f)\n",
    "for i, d in sorted(artgor_stats.items()):\n",
    "    if d['quality'] >= QUALITY_THRESHOLD:\n",
    "        train.append((d['x_fpath'], d['y'], d['quality'], d['res'], d['res_valid']))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "13897"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1050, 874, 904, 1002, 1989, 1514, 1834, 1385, 2129, 1216]"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYAAAAEACAYAAAC6d6FnAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAEQZJREFUeJzt3X+s3XV9x/HnC6uiopWYtjdSoPPHHC66jkVg4uI1TC24\nrcsSNpQEwZi4CEpcsvDDP9plWxQT2TDOGQVNa2CIZAuwOOkIniwuGT+EzroWqDGlLdgr/oBZjQvg\ne3+cb+VyPeXe29ue7+39PB/JSb/ncz/f7+dzzm2/r/P5fM7321QVkqT2HNN3ByRJ/TAAJ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9vZhgILfp94LtV9aOqehr4Z+DNPfepb1NJVgEkmQC+P9sOiykA\n7gFek+TkbjX/PKDlb3x8AdheVdf03ZE+VdWVVXVSVb2K4d+JO6vqgr771YdueL8nya93RWfR7sL4\nbuCMJMcmCcP3orUF8Zkj4luBC7vt9wKzfnAc972ADsqLxJ6R5EzgfGBbkvsZToVdWVVf67dnWgQ+\nDFyf5PnAd4GLeu5PL6rq7iQ3A/cDT3Z/fq7fXo1PkhuASeAVSXYDG4CPA19J8j6GAXnurMfxQjBJ\natNimgKSJI2RASBJjTIAJKlRBoAkNcoAkKRGGQCS1CgDQJIaZQBIUqP+H3syTJqQDZcHAAAAAElF\nTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f8c460659d0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "TRAIN_CLASSES = map(int, plt.hist(zip(*train)[1])[0])\n",
    "TRAIN_CLASSES"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.5894786284640676"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "M = max(TRAIN_CLASSES)\n",
    "m = min(TRAIN_CLASSES)\n",
    "(M - m) / float(M)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### remove the most \"unlikely resolutions\", i.e. with maximal $d(\\text{img}, \\text{class})=\\min_{r \\in R_{\\text{class}}}\\min\\{\\|r_{\\text{img}}-r\\|_2, \\|r_{\\text{img}}-r_{\\text{rotated}}\\|_2\\}$, $r=\\begin{pmatrix} h \\\\ w \\end{pmatrix}$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def resolutions(): # with all possible rotations\n",
    "    return [\n",
    "        [(1520, 2688), (2688, 1520)],\n",
    "        [(3024, 4032), (4032, 3024)],\n",
    "        [(2432, 4320), (4320, 2432)],\n",
    "        [(1040, 780), (3088, 4130), (4130, 3088), (3120, 4160), (4160, 3120)],\n",
    "        [(3120, 4160), (4160, 3120), (4160, 2340)],\n",
    "        [(4128, 2322)],\n",
    "        [(4128, 2322)],\n",
    "        [(6000, 4000)],\n",
    "        [(3264, 2448)],\n",
    "        [(3264, 2448)],\n",
    "    ]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def distance(res, c):\n",
    "    return min(min([np.sqrt((res[0]-r[0])**2+(res[1]-r[1])**2) for r in resolutions()[c]]),\n",
    "               min([np.sqrt((res[0]-r[1])**2+(res[1]-r[0])**2) for r in resolutions()[c]]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5314"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(filter(lambda (x,y,q,r,rv): rv, train)) # with correct resolutions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "8583"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(filter(lambda (x,y,q,r,rv): not rv, train))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### e.g., \"incorrect iphone4s resolutions\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYYAAAEACAYAAAC3adEgAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAE7tJREFUeJzt3X+QZWV95/H3B0Z08Mfwq5hbYYARRVArwrK7MIlJZVYM\nAlYkf4QIWZcfulvWBlejVYmDqdqB2qpNsMqSWCZS1r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dF28E3szwg5FjUVWfqqpjquo4hs+5rVX1\ngUmrM8nB7SyRJK9lOC9+LxP2uLd97E7yltZ1OnDfpNU54nyGLwhmTFKdu4ANSV6TJPz8e7n0z82l\nuJiziIstZzJ8l80OYNMK7P8rDJP0J+1BuZjhhZ/bWl3fBA4ZGf95hlf4vwucMtJ/UTuGh4ELxlzj\nO4HnGL5r626Gc45nAodNWJ2/3GrbDtwD/HHrfyNwR9vnV4FXtf5XA19r9WwD1o9s69JW/wPAGUv4\n+P8GP7/4PFF1tnpmHvN7Z34+Ju1xb9s/ieELve3AXzF8x84k1rma4ZsMXj/SN1F1Apvb8+ke4FqG\n79hc8uemH3CTJHUmaSpJkjQBDAZJUsdgkCR1DAZJUsdgkCR1DAZJUsdgkCR1DAZJUuf/A8wTJ/RX\ndwicAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f8c46065f10>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "incorrect_iphone4s = filter(lambda (x,y,q,r,rv): not rv and y == 8, train)\n",
    "dists = map(lambda (x,y,q,r,rv): distance(r, 8), incorrect_iphone4s)\n",
    "dists.sort()\n",
    "plt.hist(dists, bins=24);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1655.9619560847405,\n",
       " 1631.9571072794774,\n",
       " 1593.5294161075283,\n",
       " 1584.788944938726,\n",
       " 1584.0012626257594,\n",
       " 1580.0,\n",
       " 1580.0,\n",
       " 1580.0,\n",
       " 1580.0,\n",
       " 1580.0]"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dists[::-1][40:50]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.026346604215456676"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sum(np.asarray(dists) > 1581.)/float(len(dists))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.38114754098360654"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sum(np.asarray(dists) > 1.)/float(len(dists)) # 0 means simply landscape photos"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[(u'../data/glebs-train/train/iPhone-4s/38290361134_d74e19efa3_o.jpg',\n",
       "  8,\n",
       "  96,\n",
       "  [1698, 1858],\n",
       "  False),\n",
       " (u'../data/esato-com/train/iPhone-4s/201303121858b24wEX.jpg',\n",
       "  8,\n",
       "  96,\n",
       "  [2498, 4848],\n",
       "  False),\n",
       " (u'../data/esato-com/train/iPhone-4s/201212020931H43XZV.jpg',\n",
       "  8,\n",
       "  96,\n",
       "  [2446, 4848],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/iPhone-4s/24694324078_3435e21cd7_o.jpg',\n",
       "  8,\n",
       "  99,\n",
       "  [1500, 2000],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/iPhone-4s/24694337928_76c70409b6_o.jpg',\n",
       "  8,\n",
       "  99,\n",
       "  [1500, 2000],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/iPhone-4s/24694339268_a86b1ce6cd_o.jpg',\n",
       "  8,\n",
       "  99,\n",
       "  [1500, 2000],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/iPhone-4s/24694350208_4cf3f1ea52_o.jpg',\n",
       "  8,\n",
       "  99,\n",
       "  [1500, 2000],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/iPhone-4s/24694359098_9ae4375750_o.jpg',\n",
       "  8,\n",
       "  99,\n",
       "  [1500, 2000],\n",
       "  False)]"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "incorrect_iphone4s.sort(key=lambda (x,y,q,r,rv): -distance(r,8))\n",
    "incorrect_iphone4s[42:50]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "13246\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[1050, 874, 904, 1002, 1989, 1514, 1834, 1385, 1478, 1216]"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYAAAAEACAYAAAC6d6FnAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAD15JREFUeJzt3X2MZXV9x/H3R7a6KLrd6O5MZHWpQqltQpFEpNqmYxRZ\nsC1NExqsCS6ExKRSTJs0gE26S20TbWIbTNsYI+JioKikDduEyIbgjbFJeVC2YJcnQ2B3oTuoBepq\nbHz49o97Vi/jDLPzdM/d/b1fyc2e+51zz+97Z2fu55zfuedOqgpJUnte0ncDkqR+GACS1CgDQJIa\nZQBIUqMMAElqlAEgSY1aNACSbElyV5J9SR5McmVX35hkT5JHktyRZMPIYz6R5LEke5OcOVJ/f5JH\nu8dcsjZPSZJ0NLLYdQBJpoHpqtqb5CTga8CFwKXAd6rqb5NcBWysqquTnA9cUVXvSfJW4LqqOifJ\nRuA+4Cwg3XbOqqrn1+7pSZIWsugRQFUdqqq93fJh4CFgC8MQ2NWttqu7T/fvjd36dwMbkkwB5wF7\nqur5qnoO2ANsW8XnIklagiWdA0hyCnAm8B/AVFXNwjAkgM3daicDB0YedrCrza0/1dUkST046gDo\npn9uBT7UHQksNHeUee7XPHVeZBuSpDW27mhWSrKO4Yv/56rqtq48m2Sqqma78wTPdPWDwOtGHr4F\neLqrz8ypf3mesQwFSVqGqppvR3tBR3sE8BlgX1VdN1LbDWzvlrcDt43ULwFIcg7wXDdVdAdwbpIN\n3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kBcBB4PUj97fQ0CHdXN1h7a3A56rqtr776dHbgd9L8jjwz8A7ktzYc099OQgcqKr7uvu3MgyE\nFr0LeLyq/qeqfgz8C/C2nnvq22ySKYAk08Aziz1gkgLgXuDUJFu7s/kXAy2/4+MzwL6quq7vRvpU\nVR+uqtdX1RsY/kzcVVWX9N1XH7rD+wNJfrkrvZN2T4zvB85Jsj5JGH4vWjshPveIeDewvVt+P7Do\njuO4PwtoQV4k9jNJ3g68D3gwyf0Mp8I+XFVf6rczTYArgZuS/ALwOHBpz/30oqruSXIrcD/ww+7f\nT/Xb1fgkuRmYAV6dZD+wA/go8MUklzEMyIsW3Y4XgklSmyZpCkiSNEYGgCQ1ygCQpEYZAJLUKANA\nkhplAEhSowwASWqUASBJjfp/FGOc+9KPgkYAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f8c4633e250>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "train = filter(lambda (x,y,q,r,rv): y != 8 or (y == 8 and (rv or (not rv and distance(r, 8) < 1.))), train)\n",
    "print len(train)\n",
    "TRAIN_CLASSES = map(int, plt.hist(zip(*train)[1])[0])\n",
    "TRAIN_CLASSES"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### incorrect Samsung-Galaxy-S4 resolutions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYcAAAEACAYAAABYq7oeAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAFFxJREFUeJzt3H+s5XV95/HnC0as+GMADTNZBhhRxLrZlpoV2Npmzwoo\n0FSabKjoNvzQTcwqq627VtCkzE3/qJoYf7RdXbNThK5KFdtlkqVlJOM1666ALIxQQRh/MsMslxoZ\nNrqJVXjvH+dz8Xg/9zIz99xz7z3wfCQn8/2+v5/v9/v+Xs7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V\nj7L0cU3aq4HXJ/kO8FngNcBHgI1T0v/8b6ZU1T8wvCx5BtPz/dkH7K2qO9r8FxiGxbT0P+984H9X\n1Q/a/MT7X0/h8DXgpUlOTnIUw2tkO9a4p1ELf9vbAVzWpi8DbhypXwJPvhF+oJ3+3Qyc256cOBY4\nt9VWw18A91bVR0dqU9F/khfNP4mR5DkM75fcC3wJuKgNu3RB/5e26YuAXSP1i9vTQC8GXsrwJcyJ\nqqr3VtVJVXUKw+/0rqr6vWnpP8nR7ayTJM9leN37Hqbk+9P2vTfJy1rpbOAb09L/iDcy/OVi3uT7\nX80bKodww+U8hk/T7AGuXOt+Rvr6DMOU/QnwIHA5w7v/t7R+vwgcMzL+zxg+TfJ14JUj9cvasT0A\nXLJKvb8aeJzh0193AXe2n/NxU9L/P2s97wbuBt7X6i8Gbmu9/BXwrFZ/NvC51uetwNaRbV3Vjus+\n4LVr8D36l/z8hvRU9N/6nP/u3DP/93Javj9tv7/K8JfP3cBfM3xiZ5r6fw7DBxieP1KbeP++BCdJ\n6qyny0qSpHXCcJAkdQwHSVLHcJAkdQwHSVLHcJAkdQwHSVLHcJAkdf4/rpho0xW0a8EAAAAASUVO\nRK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f8c46065650>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "incorrect_S4 = filter(lambda (x,y,q,r,rv): not rv and y == 6, train)\n",
    "dists = map(lambda (x,y,q,r,rv): distance(r, 6), incorrect_S4)\n",
    "dists.sort()\n",
    "plt.hist(dists, bins=24);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "12907\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[1050, 874, 904, 1002, 1989, 1514, 1495, 1385, 1478, 1216]"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/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pgke4CtwGeAW5JcxDAgz1twO14IJkltmqQpIEnSGBkAktQoA0CSGmUASFKjDABJapQB\nIEmNMgAkqVEGgCQ16v8BgkmoudV26C0AAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f8c46635f10>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "train = filter(lambda (x,y,q,r,rv): y != 6 or (y == 6 and (rv or (not rv and distance(r, 6) < 1.))), train)\n",
    "print len(train)\n",
    "TRAIN_CLASSES = map(int, plt.hist(zip(*train)[1])[0])\n",
    "TRAIN_CLASSES"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### incorrect Motorola-X resolutions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1713\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYoAAAEACAYAAACtVTGuAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAFW9JREFUeJzt3WuwXWWd5/HvL8R0ayvhYhGqEyByEdSabgpLYNqemT2C\nClgt/QZFp4eLvKBaUVtraIhd1eRUd7WXKsdLOS1jTbj1iLSg3WRqaIkU7K5yRlAKIzQEEhqFhAzH\nYUyYwqmiFP7zYj9JNsdz1knOPrdwvp+qXWet/3rWXs96ziK/s9baa5OqQpKkqSxb6A5IkhY3g0KS\n1MmgkCR1MigkSZ0MCklSJ4NCktRp2qBIsiHJeJIHJ9Q/muTRJA8l+cxQfV2SbUm2JHnXUP2c1n5r\nkqtmdzckSXMl0z1HkeT3geeBm6rqd1qtB3wKOK+qfpXk9VX1bJI3ATcDbwPWAHcBJwEBtgJnATuB\nHwIXVtWjc7JXkqRZs3y6BlX1vSTHTSj/MfCZqvpVa/Nsq58P3NLqP02yDTidQVBsq6onAZLc0toa\nFJK0yM30HsUbgX+d5N4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61YTAuxwytvmdcDvbxejvw3iRPAN8A3gF8EViZwZdH\nwsv3ae84tOdxVlbVLqYen4PNDmB7Vd3f5r/FIDiW2nFxNvBEVf28nSH8HfB7wGFL9LjYY7aOgxmN\ny2IKih8CJyY5LskKBtfONi5wn+bKdQyuE35pqLYRuKRNXwLcPlS/CPY+2b67nYLeCbyzfVLmcAbX\nce+c+67Pjqr6VFUdW1XHM/hd311VfwTcA1zQml3My8fh4jZ9AXD3UP3C9umXNwAnMniQ86DSfqfb\nk7yxlc4CHmaJHRcMLjmdmeQ3k4R947DUjouJZ9ezchy0y1b/N8npbXwvGnqvqS30TZsJN3DOYfAp\noG3A1Qvdnznax7cDLzL4VNePGFx/PQc4Arir7f93gcOG1vkKg09t/Bg4bah+SRurrcBFC71vI4zJ\nv2Hfzew3MPhUxlYGn3R5Vav/BvDNtr/3AmuH1l/XxmcL8K6F3p8RxuF3GfzBtBn4NoNPrCy54wK4\npv0uHwRuZPApyCVzXAA3M/gr/wUGwXkpg5v7s3IcAG8FHmrLvrQ/ffKBO0lSp8V06UmStAgZFJKk\nTgaFJKmTQSFJ6mRQSJI6GRSSpE4GhSSpk0EhSer0/wFrDF0p2URyvAAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f8c477fc810>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "c = 4\n",
    "incorrect = filter(lambda (x,y,q,r,rv): not rv and y == c, train)\n",
    "print len(incorrect)\n",
    "dists = map(lambda (x,y,q,r,rv): distance(r, c), incorrect)\n",
    "dists.sort()\n",
    "plt.hist(dists, bins=24);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[184.56435192094924, 184.56435192094924, 184.56435192094924, 184.56435192094924, 184.56435192094924, 184.56435192094924, 184.56435192094924, 184.56435192094924, 184.56435192094924, 184.56435192094924]\n"
     ]
    }
   ],
   "source": [
    "c = 4\n",
    "dists = map(lambda (x,y,q,r,rv): distance(r, c), incorrect)\n",
    "dists.sort()\n",
    "print dists[500:510]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[(u'../data/glebs-train/train/Motorola-X/24800884010_e8a4414391_o.jpg',\n",
       "  4,\n",
       "  95,\n",
       "  [2432, 4320],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Motorola-X/24801148050_c2e5e2bc3b_o.jpg',\n",
       "  4,\n",
       "  95,\n",
       "  [2432, 4320],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Motorola-X/24886935300_260bef7313_o.jpg',\n",
       "  4,\n",
       "  95,\n",
       "  [2432, 4320],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Motorola-X/24908486461_4b67737261_o.jpg',\n",
       "  4,\n",
       "  95,\n",
       "  [2432, 4320],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Motorola-X/24917793486_a84a24dd28_o.jpg',\n",
       "  4,\n",
       "  95,\n",
       "  [4320, 2432],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Motorola-X/24978362412_198f73d5df_o.jpg',\n",
       "  4,\n",
       "  95,\n",
       "  [2432, 4320],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Motorola-X/25003330771_e554aa4e98_o.jpg',\n",
       "  4,\n",
       "  95,\n",
       "  [4320, 2432],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Motorola-X/25003677326_f67c4fb2fa_o.jpg',\n",
       "  4,\n",
       "  95,\n",
       "  [2432, 4320],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Motorola-X/25033310134_a18f64e4e0_o.jpg',\n",
       "  4,\n",
       "  95,\n",
       "  [4320, 2432],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Motorola-X/25033332724_18718bc9cc_o.jpg',\n",
       "  4,\n",
       "  95,\n",
       "  [2432, 4320],\n",
       "  False)]"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "incorrect.sort(key=lambda (x,y,q,r,rv): distance(r,4))\n",
    "incorrect[500:510]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### add images with Droid Maxx resolution to its class\n",
    "### UPD: no"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "new_train = []\n",
    "for x,y,q,r,rv in train:\n",
    "    if y == 4 and r and distance(r, 2) < 0.01:\n",
    "        new_train.append((x,2,q,r,rv))\n",
    "    else:\n",
    "        new_train.append((x,y,q,r,rv))\n",
    "train = new_train"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### filter Moto X"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "12653\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[1050, 874, 2042, 1002, 597, 1514, 1495, 1385, 1478, 1216]"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYAAAAEACAYAAAC6d6FnAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAEQBJREFUeJzt3X+s3XV9x/HnC6tWRSsxbW+kQOePOVx0HYvAxMVrmFpw\nW5clbCgJgjFxEZS4ZOGHf7TLtigmsmGcMyqa1oCIZAuwOOkIniwuGT+ETlwL1JjSFuwVf8CsRgP4\n3h/nW7lcT7ntvb3ne3s/z0dy0u/53M/3+/mc7z33vM7n8znf01QVkqT2HNN3ByRJ/TAAJKlRBoAk\nNcoAkKRGGQCS1CgDQJIaNWsAJFmT5PYk25Pcl+QDXfnGJHuT3NPd1k/b5/IkO5PsSPK2aeXrk9yf\n5MEkly7MQ5IkH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C4XPi9qo6v+9+9aEb3u9J8ptd0Zm0uzC+Gzg9yfIk\nYXguWlsQnzkivhm4oNt+NzDrG8dxfxfQQXmR2NOSnAGcB9yX5F6GU2FXVNXX+u2ZFoEPAtcmeS7w\nXeDCnvvTi6q6M8mNwL3AE92/n+m3V+OT5DpgEnhZkt3ARuCjwFeSvIdhQJ4z63G8EEyS2rSYpoAk\nSWNkAEhSowwASWqUASBJjTIAJKlRBoAkNcoAkKRGGQCS1Kj/B+ErCvffRbOgAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f8c4742e450>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "c = 4\n",
    "train = filter(lambda (x,y,q,r,rv): y != c or (y == c and (rv or (not rv and distance(r, c) < 1.))), train)\n",
    "print len(train)\n",
    "TRAIN_CLASSES = map(int, plt.hist(zip(*train)[1])[0])\n",
    "TRAIN_CLASSES"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### class 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1240\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYcAAAEACAYAAABYq7oeAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAE0dJREFUeJzt3H+s5XWd3/HnaxgRWZcBNMykDDCuUlCzltoqdO0md5VF\nwNQxm2Bx24A/SEyF1S1J18FNCpM22cUsWVaMa5al7LBZpQrpQlNSkOI1sXFQAwOsIDPWHzBMubrh\nV5YmivDuH+dz8Xg/5zLcc+6Pc+H5SE7m+/2cz/f7fX+/53vP63x/TaoKSZKGbVjrAiRJ08dwkCR1\nDAdJUsdwkCR1DAdJUsdwkCR1DhoOSa5JMpfk3qG2Tyd5IMmeJDcmOWLovUuS7GvvnzHUfmaS7ybZ\nm+STy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wHSVLHcJAkdQwHSVLHcJAkdQwHSVLHcJAkdQwHSVLn/wML8kX4vo0l\nFQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f8c460ae4d0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "c = 2\n",
    "incorrect = filter(lambda (x,y,q,r,rv): not rv and y == c, train)\n",
    "print len(incorrect)\n",
    "dists = map(lambda (x,y,q,r,rv): distance(r, c), incorrect)\n",
    "dists.sort()\n",
    "plt.hist(dists, bins=24);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]\n"
     ]
    }
   ],
   "source": [
    "c = 2\n",
    "dists = map(lambda (x,y,q,r,rv): distance(r, c), incorrect)\n",
    "dists.sort()\n",
    "print dists[:30]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "12550\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[1050, 874, 1939, 1002, 597, 1514, 1495, 1385, 1478, 1216]"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYAAAAEACAYAAAC6d6FnAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAD25JREFUeJzt3X+s3XV9x/HnSzotinaNtvdGqq2/5tgShyQq0y27RpGC\n21iWsOBMoBASk8kwW7IALlnL3BJd4hbMthgjYjEyf5AtdAmRhuCJcclAkA5c+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wJingKrqp0kuA3YzPP5wrS/+ktSPse4BSJImx0SdCexJYkNJNiW5LcneJPcmubzvnvqW\n5EVJvp1kV9+99CnJuiRfTXJfkv9O8o6+e+pLkj9L8p0k9yT5YpIX993TuCS5NslskntGauuT7E7y\nQJJbkqxbbDsTEwCeJPY8PwH+vKp+DfhN4MMNPxZHfATY23cTE+Aa4OaqOg34DaDJKdQkrwb+FDij\nqt7CcDr7gn67GqvrGL5WjroSuLWq3gzcBly12EYmJgDwJLGfq6pDVbWnWz7M8D95s+dLJNkEnAt8\ntu9e+pTk5cBvV9V1AFX1k6r6v57b6tNJwMuSrAFeCjzecz9jU1XfBJ6cUz4P2Nkt7wT+YLHtTFIA\neJLYPJJsAU4Hbu+3k179A/AXzHPOSGNeD3wvyXXddNhnkpzcd1N9qKrHgU8C+4HHgKeq6tZ+u+rd\nxqqaheGbSGDDYjeYpABY0kliLUlyCnAj8JFuT6A5Sd4PzHZ7RGH+50kr1gBnAP9UVWcAP2K429+c\nJL/M8B3vZuDVwClJ/rjfro4/kxQAB4HXjlzfREO7dHN1u7U3Al+oqpv67qdH7wJ+P8kjwL8A705y\nfc899eUgcKCq7uyu38gwEFr0XuCRqvrfqvop8K/AO3vuqW+zSaYAkkwDTyx2g0kKgG8Bb0yyuTua\nfwHQ8ic+Pgfsrapr+m6kT1X10ap6bVW9nuFz4raqurDvvvrQ7d4fSPIrXek9tHtgfD9wZpK1ScLw\nsWjtgPjcPeJdwLZu+SJg0TeO4/4uoAV5kthzkrwL+CBwb5K7GU6FfbSqvtZvZ5oAlwNfTPJLwCPA\nxT3304uquiPJjcDdwLPdv5/pt6vxSXIDMAO8Msl+YDvwceCrSS5hGJDnL7odTwSTpDZN0hSQJGmM\nDABJapQBIEmNMgAkqVEGgCQ1ygCQpEYZAJLUKANAkhr1/xD5E6sgpauNAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f8c47518990>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "c = 2\n",
    "train = filter(lambda (x,y,q,r,rv): y != c or (y == c and (rv or (not rv and distance(r, c) < 0.1))), train)\n",
    "print len(train)\n",
    "TRAIN_CLASSES = map(int, plt.hist(zip(*train)[1])[0])\n",
    "TRAIN_CLASSES"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### class 9"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "781\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYMAAAEACAYAAABRQBpkAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAE3ZJREFUeJzt3X+M3PV95/HnyzikIYEF0rK+2oAbSqC9P+pQHbhNTzcU\nmgDVxfnH+dGrjCGnQ6eipK3UxuT+wKv+0RApSoLaBlWlOZNLoAQutaW6tYOciXSnQJsDBy44xiRp\nsPF5aQqmDY0Qhff9MZ81w2bWO2vPeNfm+ZBG/nw/8/nO9/3Zj3de+/3OzG6qCknS69uyxS5AkrT4\nDANJkmEgSTIMJEkYBpIkDANJEkOEQZK3J3kkycPt3+eTfDjJOUl2JtmbZEeSib59bk+yL8nuJGvG\nOwVJ0vGaNwyq6omqekdVXQb8IvAC8GVgE/BAVV0C7AJuAUhyLXBRVV0M3ATcMa7iJUmjsdDLRFcD\n36mq/cA6YEvr39K2af/eBVBVDwETSSZHUKskaUwWGgbvB77Y2pNVNQ1QVYeA81r/SmB/3z5Ptz5J\n0hI1dBgkeQPwHuBLrWuu32ORAX3+zgtJWsKWL2DstcD/qaoftO3pJJNVNZ1kBfBM6z8AnN+33yrg\n4OwHS2JASNIxqKpBP3Qfl4VcJvogcHff9jZgY2tvBLb29W8ASLIWODxzOWm2qjplb7feeuui1+D8\nnJvzO/Vu4zLUmUGSN9F78fi/9HXfBtyb5EbgKWA9QFVtT3JdkifpvfP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E769UtyNr1f+XIhvW/6N9O7bDLbybp2w1joei3ZuSb5b8BLVXX3TNeA\nYfPNba7v2zktRhgcAC7o214FHFyEOhasvQhzH73Tt62tezrJZLt/Bb1Tc+jN8/y+3WfmuVTn/07g\nPUm+C9wN/CrwaWAivV8+CK+t9cj80vtsyURVPcfc815sB4D9VfWNtn0/vXA4FdbvauC7VfVs+0n/\ny8AvA2efImvXb1TrtSTnmuR64DrgN/q6FzS3qvoBc6/9nBYjDP4O+NkkFyY5nd61um2LUMex+HN6\n1xk/09e3DdjY2huBrX39G+DIp7IPt9PbHcCvtXe2nEPv2u6O8Zd+dFX1saq6oKreRm9NdlXVbwJf\nBda3Ydfz2vld39rrgV19/R9o71j5GeBn6X3wcFG1r/3+JG9vXVcB3+LUWL+ngLVJfiJJeHVup8La\nzf4pdyTr1S4x/VOSy9vXbEPfY50or5lbkmuA3wfeU1Uv9o2ba10GPZfOzGEXg9d+bov0otA19N6N\nsw/YtBg1HEPN7wRepveK/SP0rsleA5wLPNDm8xXg7L59/ojeq/3fBC7r69/Y5v4EsGGx5zZgrv+B\nV19A/hl677p4gt47FN7Q+t8I3Nvm8SCwum//W9q89wDvWuz59NX1C+0baDfwP+m9w+SUWD/g1vb1\nfhTYQu/dJSf12gFfpPcT7Yv0Au8Gei+Sj2S9gF8EHmv3fWYJzG0fvTcCPNxufzLfujDHc+lca3+0\nmx86kyT5Zy8lSYaBJAnDQJKEYSBJwjCQJGEYSJIwDCRJGAaSJOD/A7d1Foks4rSdAAAAAElFTkSu\nQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f8c46e54d10>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "c = 9\n",
    "incorrect = filter(lambda (x,y,q,r,rv): not rv and y == c, train)\n",
    "print len(incorrect)\n",
    "dists = map(lambda (x,y,q,r,rv): distance(r, c), incorrect)\n",
    "dists.sort()\n",
    "plt.hist(dists, bins=24);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "12428\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[1050, 874, 1939, 1002, 597, 1514, 1495, 1385, 1478, 1094]"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYAAAAEACAYAAAC6d6FnAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAD1RJREFUeJzt3X+s3XV9x/HnSzopinaNtvdGqq2Kc26JQxKV6ZZdg0jB\nbSxLWHAmUIiJyWSSLVkoLlnL3BJd4hbMthAjYmtgqGQLXUJsQ/DEuGQgSgeu/DIG28J6VQbMaiSo\n7/1xvpXD9V7u7b3t+Z7283wkJ/2ez/me7+d9vj09r+/38z2f01QVkqT2vKjvAiRJ/TAAJKlRBoAk\nNcoAkKRGGQCS1CgDQJIatWgAJNmQ5M4k+5Lcn+TDXfvaJHuSPJRkd5I1I8/5ZJJHkuxNctZI+2VJ\nHu6ec+nxeUmSpKXIYvMAkkwD01W1N8npwNeBi4DLgSeq6u+SXA2sraqtSS4Arqyq9yZ5O3BdVZ2T\nZC1wD3A2kG47Z1fV08fv5UmSFrLoGUBVHaqqvd3yYeABYAPDENjRrbaju0/3585u/buANUmmgPOB\nPVX1dFU9BewBNh/D1yJJOgpHdQ0gySbgLOA/gamqmoVhSADru9XOAA6MPO1g1za3/bGuTZLUgyUH\nQDf8cytwVXcmsNDYUea5X/O08wLbkCQdZ6uWslKSVQw//D9XVbd1zbNJpqpqtrtO8N2u/SDw6pGn\nbwAe79pn5rR/eZ6+DAVJWoaqmu9Ae0FLPQP4DLCvqq4badsFbOmWtwC3jbRfCpDkHOCpbqhoN3Be\nkjXdBeHzurZfUFXeqti2bVvvNUzKzX3hvnBfvPBtORY9A0jyTuD9wP1J7mU4bPMR4OPAF5JcAewH\nLu4+vG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y8BWv7Gx2eAfVV1Xd+F9KmqPlJVr6mq1zF8\nT9xZVZf2XVcfutP7A0l+pWs6l3YvjO8HzkmyOkkY7ovWLojPPSPeBWzpli8DFj1wHPdvAS3ISWLP\nSfJO4P3A/UnuZTgU9pGq+lK/lWkCfBi4KckvAd8GLu+5nl5U1d1JbgXuBZ7t/vxUv1WNT5KbgRng\nFUn2A9uAjwFfTHIFw4C8eNHtOBFMkto0SUNAkqQxMgAkqVEGgCQ1ygCQpEYZAJLUKANAkhplAEhS\nowwASWrU/wOTaxOrlgY6vQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f8c46e49250>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "c = 9\n",
    "train = filter(lambda (x,y,q,r,rv): y != c or (y == c and (rv or (not rv and distance(r, c) < 1.))), train)\n",
    "print len(train)\n",
    "TRAIN_CLASSES = map(int, plt.hist(zip(*train)[1])[0])\n",
    "TRAIN_CLASSES"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### class 7"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1082\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYAAAAEACAYAAAC6d6FnAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAE0ZJREFUeJzt3X+sZOV93/H3Z1mbwtpewC67FRjf2CGYVFEwbWEbt/Im\nEMdgJeQfHNNa/LAjWRXIbiMlXlypC6pUBUtRMCI1ikpcnCYGGzdmm2KDrWUstTLEllmbNQss/sWC\nvRc7gCuDhBL22z/muXi4vjd37u7M3ss875c02meeec6Z5zs7ez5zzpkzm6pCktSfDWs9AUnS2jAA\nJKlTBoAkdcoAkKROGQCS1CkDQJI6NVYAJNmc5NNJ9iX5ZpJzk5yY5O4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8E7W1Ohbelw8sbDNm5b3Z5vXLDD8c7wH+J8Nv8ky9\nPi8Ek6ROvaz+S0hJ0uQYAJLUKQNAkjplAEhSpwwASeqUASBJnTIAJKlTBoAkder/A9A949XKtgBI\nAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f8c460f9050>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "c = 7\n",
    "incorrect = filter(lambda (x,y,q,r,rv): not rv and y == c, train)\n",
    "print len(incorrect)\n",
    "dists = map(lambda (x,y,q,r,rv): distance(r, c), incorrect)\n",
    "dists.sort()\n",
    "plt.hist(dists, bins=24);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[(u'../data/glebs-train/train/Sony-NEX-7/24513930567_55f14618b1_o.jpg',\n",
       "  7,\n",
       "  100,\n",
       "  [3744, 5617],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Sony-NEX-7/38142165914_cda10d75f7_o.jpg',\n",
       "  7,\n",
       "  99,\n",
       "  [3540, 6000],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Sony-NEX-7/38685299801_bef6ff20fb_o.jpg',\n",
       "  7,\n",
       "  96,\n",
       "  [3750, 5625],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Sony-NEX-7/37541197882_14bca12c58_o.jpg',\n",
       "  7,\n",
       "  99,\n",
       "  [5635, 3737],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Sony-NEX-7/38653248512_b91ed4e845_o.jpg',\n",
       "  7,\n",
       "  96,\n",
       "  [5630, 3753],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Sony-NEX-7/37967530344_a1f8336856_o.jpg',\n",
       "  7,\n",
       "  96,\n",
       "  [5646, 3764],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Sony-NEX-7/37112580226_c98fb4c5c2_o.jpg',\n",
       "  7,\n",
       "  96,\n",
       "  [5600, 4000],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Sony-NEX-7/38110805492_fa9f7b999a_o.jpg',\n",
       "  7,\n",
       "  93,\n",
       "  [3603, 6000],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Sony-NEX-7/37967044094_7f21ef19e5_o.jpg',\n",
       "  7,\n",
       "  96,\n",
       "  [5697, 3798],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Sony-NEX-7/26909773289_d85a255141_o.jpg',\n",
       "  7,\n",
       "  96,\n",
       "  [3809, 5714],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Sony-NEX-7/38653228162_597508f187_o.jpg',\n",
       "  7,\n",
       "  96,\n",
       "  [3813, 5720],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Sony-NEX-7/37875538205_8d31186cf8_o.jpg',\n",
       "  7,\n",
       "  99,\n",
       "  [5710, 3832],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Sony-NEX-7/38653315692_653366e3b9_o.jpg',\n",
       "  7,\n",
       "  96,\n",
       "  [3821, 5731],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Sony-NEX-7/38814039471_3e9b8b18b1_o.jpg',\n",
       "  7,\n",
       "  99,\n",
       "  [3835, 5752],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Sony-NEX-7/24813019838_94e5739e02_o.jpg',\n",
       "  7,\n",
       "  96,\n",
       "  [3854, 5781],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Sony-NEX-7/26908977599_cea849c600_o.jpg',\n",
       "  7,\n",
       "  96,\n",
       "  [3854, 5781],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Sony-NEX-7/38685792691_ab7e0b4847_o.jpg',\n",
       "  7,\n",
       "  96,\n",
       "  [5789, 3859],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Sony-NEX-7/37179667870_fa1a221716_o.jpg',\n",
       "  7,\n",
       "  93,\n",
       "  [3757, 5988],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Sony-NEX-7/37797496805_e318a775bc_o.jpg',\n",
       "  7,\n",
       "  96,\n",
       "  [3865, 5798],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Sony-NEX-7/37797917115_65e841023e_o.jpg',\n",
       "  7,\n",
       "  96,\n",
       "  [5798, 3865],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Sony-NEX-7/38685830931_7ba83a9700_o.jpg',\n",
       "  7,\n",
       "  96,\n",
       "  [3865, 5798],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Sony-NEX-7/37875536925_dfd55732fa_o.jpg',\n",
       "  7,\n",
       "  99,\n",
       "  [3810, 5878],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Sony-NEX-7/37875545235_fac44a3c7d_o.jpg',\n",
       "  7,\n",
       "  99,\n",
       "  [3812, 5908],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Sony-NEX-7/26909041769_f03c692a91_o.jpg',\n",
       "  7,\n",
       "  96,\n",
       "  [3888, 5832],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Sony-NEX-7/24544949827_3b53c0085e_o.jpg',\n",
       "  7,\n",
       "  100,\n",
       "  [3888, 5833],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Sony-NEX-7/26986545869_c0cb61bef1_o.jpg',\n",
       "  7,\n",
       "  99,\n",
       "  [3833, 5912],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Sony-NEX-7/38685813721_c9fc810953_o.jpg',\n",
       "  7,\n",
       "  96,\n",
       "  [5848, 3899],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Sony-NEX-7/26909017229_5c434145b3_o.jpg',\n",
       "  7,\n",
       "  96,\n",
       "  [5848, 3899],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Sony-NEX-7/26909532029_0cfe6aeeb7_o.jpg',\n",
       "  7,\n",
       "  96,\n",
       "  [5848, 3899],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Sony-NEX-7/24812938958_b12e9a1c23_o.jpg',\n",
       "  7,\n",
       "  96,\n",
       "  [5849, 3899],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Sony-NEX-7/24812936948_7574fa719b_o.jpg',\n",
       "  7,\n",
       "  96,\n",
       "  [5856, 3904],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Sony-NEX-7/26986562239_38e8c7b642_o.jpg',\n",
       "  7,\n",
       "  99,\n",
       "  [5860, 3904],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Sony-NEX-7/38533117315_53ba74e244_o.jpg',\n",
       "  7,\n",
       "  100,\n",
       "  [3911, 5867],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Sony-NEX-7/24513794497_ee37c03cd9_o.jpg',\n",
       "  7,\n",
       "  100,\n",
       "  [3922, 5884],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Sony-NEX-7/26626262579_1b3caef0f6_o.jpg',\n",
       "  7,\n",
       "  99,\n",
       "  [4000, 5887],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Sony-NEX-7/24813154588_60f1db51d2_o.jpg',\n",
       "  7,\n",
       "  96,\n",
       "  [5916, 3944],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Sony-NEX-7/38652752822_012f38046e_o.jpg',\n",
       "  7,\n",
       "  96,\n",
       "  [5950, 3967],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Sony-NEX-7/36601955143_61e746acc8_o.jpg',\n",
       "  7,\n",
       "  99,\n",
       "  [5981, 3987],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Sony-NEX-7/38685802261_a64f2ff2e9_o.jpg',\n",
       "  7,\n",
       "  96,\n",
       "  [5992, 3995],\n",
       "  False),\n",
       " (u'../data/esato-com/train/Sony-NEX-7/201308281543a07Z13.jpg',\n",
       "  7,\n",
       "  95,\n",
       "  [4000, 6000],\n",
       "  False),\n",
       " (u'../data/esato-com/train/Sony-NEX-7/201308281542u833tY.jpg',\n",
       "  7,\n",
       "  95,\n",
       "  [4000, 6000],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Sony-NEX-7/37593141095_b2c6bfbf69_o.jpg',\n",
       "  7,\n",
       "  95,\n",
       "  [4000, 6000],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Sony-NEX-7/37593143425_d0f70773d0_o.jpg',\n",
       "  7,\n",
       "  95,\n",
       "  [4000, 6000],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Sony-NEX-7/37593144275_659d2cd101_o.jpg',\n",
       "  7,\n",
       "  95,\n",
       "  [4000, 6000],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Sony-NEX-7/37593154265_f155f028fc_o.jpg',\n",
       "  7,\n",
       "  95,\n",
       "  [4000, 6000],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Sony-NEX-7/37593155425_0cc03bfe4b_o.jpg',\n",
       "  7,\n",
       "  95,\n",
       "  [4000, 6000],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Sony-NEX-7/37593156215_e813738885_o.jpg',\n",
       "  7,\n",
       "  95,\n",
       "  [4000, 6000],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Sony-NEX-7/37593157235_5c58eb5e1a_o.jpg',\n",
       "  7,\n",
       "  95,\n",
       "  [4000, 6000],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Sony-NEX-7/37593159505_63cc78c811_o.jpg',\n",
       "  7,\n",
       "  95,\n",
       "  [4000, 6000],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Sony-NEX-7/37593162095_d092743582_o.jpg',\n",
       "  7,\n",
       "  95,\n",
       "  [4000, 6000],\n",
       "  False)]"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dists[500:600]\n",
    "incorrect.sort(key=lambda (x,y,q,r,rv): -distance(r,c))\n",
    "incorrect[550:600]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "11839\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[1050, 874, 1939, 1002, 597, 1514, 1495, 796, 1478, 1094]"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYAAAAEACAYAAAC6d6FnAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAD0xJREFUeJzt3X+MHGd9x/H3h7jEgYBrgX0nYrCBUEor0RAJSKFVD0GI\nE9qmqpQqFCk4ERJSSUGtVJFQqXZKK0ElWgW1FUKE4CBSfkSt4koRsaKwQlRqQiAuoc4vhILtpD5+\nNEkxiIgf3/6xY7I57nLnO3tm7ef9klaefXZ2nu/Onfcz88w+e6kqJEntecbQBUiShmEASFKjDABJ\napQBIEmNMgAkqVEGgCQ1atkASLIlye1J9ie5J8m7u/aNSfYmuT/JrUk2TDznw0keTLIvyTkT7W9P\n8kD3nMtOzEuSJK1ElpsHkGQWmK2qfUnOBL4CXAxcDnyvqv4uyXuBjVV1VZILgSur6i1JXgtcW1Xn\nJdkI3AWcC6TbzrlV9fiJe3mSpKUsewZQVYeral+3fAS4F9jCOAR2d6vt7u7T/XtDt/4dwIYkM8AF\nwN6qeryqHgP2AtuP42uRJB2DY7oGkGQbcA7wn8BMVc3DOCSAzd1qZwEHJ552qGtb2P5w1yZJGsCK\nA6Ab/rkJeE93JrDU2FEWuV+LtPM025AknWDrVrJSknWM3/w/WVU3d83zSWaqar67TvDtrv0Q8MKJ\np28BHuna5xa0f2GRvgwFSVqFqlrsQHtJKz0D+Diwv6qunWjbA+zolncAN0+0XwaQ5DzgsW6o6Fbg\n/CQbugvC53dtv6CqvFWxc+fOwWuYlpv7wn3hvnj622osewaQ5PXA24B7ktzNeNjmfcAHgc8muQI4\nAFzSvXnfkuSiJN8AfsD400JU1aNJ3s/4k0AFXFPji8GSpAEsGwBV9R/AaUs8/K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n9weT/ErX9EbavTB+ADgvyfokYbwvWrsgvvCMeA+wo1t+O7DsgWPf3wW0JCeJPSnJ64G3Afck\nuZvxUNj7qurzw1amKfBu4FNJfgn4JnD5wPUMoqruTHITcDfw4+7fjw5bVX+S3AjMAc9LcgDYCXwA\n+FySKxgH5CXLbseJYJLUpmkaApIk9cgAkKRGGQCS1CgDQJIaZQBIUqMMAElqlAEgSY0yACSpUf8P\n28wZq4YEFDEAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f8c4683f9d0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "c = 7\n",
    "train = filter(lambda (x,y,q,r,rv): y != c or (y == c and (rv or (not rv and distance(r, c) < 1.))), train)\n",
    "print len(train)\n",
    "TRAIN_CLASSES = map(int, plt.hist(zip(*train)[1])[0])\n",
    "TRAIN_CLASSES"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### class 5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1229\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYAAAAEACAYAAAC6d6FnAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAE5ZJREFUeJzt3W+MpWd53/Hvb72Y2vxZbIhnKq/tDcQYUlWx3dZ2oVFP\nYodgR8V54wBtZK8hqlNhQRspxSYvvKO+iSNFgJUWK4pDFwoYY0q8Up3aWMtBaoUNlF1YYbOs+edd\nOzuG4iXCaVBjX31x7lmOl5numd1zPOO5vx/paO7nOvd55rpnz87vPM+ZZyZVhSSpP5vWugFJ0tow\nACSpUwaAJHXKAJCkThkAktQpA0CSOnXcAEjy2iR7knylffxRkncnOSPJ/Un2J7kvyZaxx9yW5ECS\nvUkunO0SJEkn4rgBUFXfrKqLqupi4B8BTwOfAW4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1rrtR2zzn/OT98E3hBra+tY\nel7uW/qesVGem62vX2L04ngv8F8Z/STPzNfnhWCS1Cn/JKQkdcoAkKROGQCS1CkDQJI6ZQBIUqcM\nAEnqlAEgSZ0yACSpU/8PgzFbxEc3Ab0AAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f8c4683f290>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "c = 5\n",
    "incorrect = filter(lambda (x,y,q,r,rv): not rv and y == c, train)\n",
    "print len(incorrect)\n",
    "dists = map(lambda (x,y,q,r,rv): distance(r, c), incorrect)\n",
    "dists.sort()\n",
    "plt.hist(dists, bins=24);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dists[:9]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1783.1850717185807,\n",
       " 2240.1901704989245,\n",
       " 2240.1901704989245,\n",
       " 2240.1901704989245,\n",
       " 2240.1901704989245,\n",
       " 2240.1901704989245,\n",
       " 2240.1901704989245,\n",
       " 2240.1901704989245,\n",
       " 2240.1901704989245,\n",
       " 2240.1901704989245,\n",
       " 2240.1901704989245,\n",
       " 2240.1901704989245,\n",
       " 2240.1901704989245,\n",
       " 2240.1901704989245,\n",
       " 2246.0650035116973,\n",
       " 2377.6433710714482,\n",
       " 2389.5145950590049,\n",
       " 2465.6481906387212,\n",
       " 2533.3432455946431,\n",
       " 2533.3432455946431,\n",
       " 2533.3432455946431,\n",
       " 2533.3432455946431,\n",
       " 2619.1983506408978,\n",
       " 2643.598305340658,\n",
       " 3210.4834526905756,\n",
       " 3915.9975740544069,\n",
       " 4759.2541432455573,\n",
       " 4791.6948984675555,\n",
       " 4861.0744697031741,\n",
       " 5029.1315353647296]"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dists[-30:]#, dists[230:260]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[(u'../data/glebs-train/train/Samsung-Galaxy-Note3/35117221375_929f93ce27_o.jpg',\n",
       "  5,\n",
       "  96,\n",
       "  [1836, 3264],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Samsung-Galaxy-Note3/35117221805_b6d7eaaf7a_o.jpg',\n",
       "  5,\n",
       "  96,\n",
       "  [1836, 3264],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Samsung-Galaxy-Note3/35117222025_ef03a23839_o.jpg',\n",
       "  5,\n",
       "  96,\n",
       "  [1836, 3264],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Samsung-Galaxy-Note3/35117222445_45b64bb3fe_o.jpg',\n",
       "  5,\n",
       "  96,\n",
       "  [1836, 3264],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Samsung-Galaxy-Note3/35117222905_5aa70485e9_o.jpg',\n",
       "  5,\n",
       "  96,\n",
       "  [1836, 3264],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Samsung-Galaxy-Note3/35231019683_321c9f0a34_o.jpg',\n",
       "  5,\n",
       "  93,\n",
       "  [3264, 1836],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Samsung-Galaxy-Note3/35569476706_12ecc6623c_o.jpg',\n",
       "  5,\n",
       "  96,\n",
       "  [1836, 3264],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Samsung-Galaxy-Note3/35754448775_772a29eaca_o.jpg',\n",
       "  5,\n",
       "  96,\n",
       "  [1836, 3264],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Samsung-Galaxy-Note3/35999662456_1cbe0bb2b5_o.jpg',\n",
       "  5,\n",
       "  93,\n",
       "  [1836, 3264],\n",
       "  False),\n",
       " (u'../data/glebs-train/train/Samsung-Galaxy-Note3/36041325785_0c7c5e0d6b_o.jpg',\n",
       "  5,\n",
       "  93,\n",
       "  [1836, 3264],\n",
       "  False)]"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "incorrect.sort(key=lambda (x,y,q,r,rv): -distance(r,5))\n",
    "incorrect[130:140]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### same ratio as in training set, keep"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "11774\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[1050, 874, 1939, 1002, 597, 1449, 1495, 796, 1478, 1094]"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYAAAAEACAYAAAC6d6FnAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAADz9JREFUeJzt3X+s3XV9x/HnCzopCnYNtreRalFxzi1xSKIy3bJrFCm4\njWUJC84ECzExmUyzJYvgkrXMLZElboFsizEiFiNTIFvoEiINwRPjkvFD6cSVX8ZgW1ivPwbMajT+\neO+P860ervdyb+9tv9/Tfp6P5KTf8znf8/28z/fentf3+/mez7mpKiRJ7Tlp6AIkScMwACSpUQaA\nJDXKAJCkRhkAktQoA0CSGrVkACTZnOTuJHuTPJjkfV37+iS7kzyS5M4k6yaec32Sx5LsSXLORPu7\nkjzaPeeyY/OSJEnLkaXmASTZBGyqqj1JTgO+BFwMXA58p6r+LskHgPVVdVWSC4Erq+rtSd4AXFdV\n5yVZD9wPnAuk2865VfXMsXt5kqTFLHkGUFUHq2pPt3wIeAjYzDgEdnar7ezu0/17U7f+PcC6JDPA\nBcDuqn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WcA9wzbCWD+gfgL1hgzkhjXg58O8mN3XDYx5KcOnRRQ6iqJ4GPAPuA\nJ4Cnq+quYasa3MaqmoPxQSSwYaknTFMALGuSWEuSnAbcBry/OxNoTpK3A3PdGVFY+PekFWuAc4F/\nqqpzge8zPu1vTpJfZnzEuwV4MXBakj8etqrjzzQFwAHgpRP3N9PQKd183WntbcCnqur2oesZ0JuA\n30/ydeBfgDcnuWngmoZyANhfVfd3929jHAgteivw9ar636r6CfCvwBsHrmloc0lmAJJsAr651BOm\nKQDuA85OsqW7mn8p0PInPj4B7K2q64YuZEhV9cGqemlVvZzx78TdVXXZ0HUNoTu935/kV7qmt9Du\nhfF9wHlJ1iYJ433R2gXx+WfEu4Bt3fK7gCUPHPv+LqBFOUns55K8CXgn8GCSBxgPhX2wqj43bGWa\nAu8DPp3kl4CvA5cPXM8gqureJLcBDwA/6v792LBV9SfJzcAscEaSfcB24MPArUmuYByQlyy5HSeC\nSVKbpmkISJLUIwNAkhplAEhSowwASWqUASBJjTIAJKlRBoAkNcoAkKRG/T/DVy7qxg9KJgAAAABJ\nRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f8c4b9c6c50>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "c = 5\n",
    "train = filter(lambda (x,y,q,r,rv): y != c or (y == c and (rv or (not rv and ((distance(r, c) < 1.) or (773. < distance(r, c) < 992.))))), train)\n",
    "print len(train)\n",
    "TRAIN_CLASSES = map(int, plt.hist(zip(*train)[1])[0])\n",
    "TRAIN_CLASSES"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### class 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "33\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAEACAYAAABI5zaHAAAABHNCSVQICAgIfAhk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0TO87vlc4HrVjsjQFW9rqqeXFVPAX4euK6qfqFvOZNs6X5b\nI8mjGc0V76Fnj3s3xpeTPLVb9TzgM33L2Xkpox/oh/Qt413AmUm+I0n41n3Zq+cmQJKTun+fDLyE\n0f06u/tzBicGLmP0E+TrjO7YlzM6mfERRq9KuRY4ftH2fwb8C/Ap4LQ1OnlxFvBNRr/63MpoDu5s\n4HE9y/mMLttuRmfSf7tb/13ATYx+sr8L2NSt3wy8G7iD0TmEHWuR84jMP8a3Tqj2KmeX59Bjvge4\nqFvfq8e9G/f7gU90ef+O0atlepUTeBSjk+aPWbSuVxm7cXcxOuF4G3ApsKlvz81u7BsYzb3fCgxm\nfX96EZMkNci32ZOkBlnuktQgy12SGmS5S1KDLHdJapDlLkkNstwlqUGWuyQ16H8BXI+y5xOZmqMA\nAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f8c460ae350>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "c = 0\n",
    "incorrect = filter(lambda (x,y,q,r,rv): not rv and y == c, train)\n",
    "print len(incorrect)\n",
    "dists = map(lambda (x,y,q,r,rv): distance(r, c), incorrect)\n",
    "dists.sort()\n",
    "plt.hist(dists, bins=24);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### simply remove all incorrect"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "11741\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[1017, 874, 1939, 1002, 597, 1449, 1495, 796, 1478, 1094]"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYAAAAEACAYAAAC6d6FnAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAD15JREFUeJzt3W2MXFd9x/H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
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f8c49a15a50>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "c = 0\n",
    "train = filter(lambda (x,y,q,r,rv): y != c or (y == c and rv), train)\n",
    "print len(train)\n",
    "TRAIN_CLASSES = map(int, plt.hist(zip(*train)[1])[0])\n",
    "TRAIN_CLASSES"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### class 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "206\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYAAAAEACAYAAAC6d6FnAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAEE5JREFUeJzt3X+sX3V9x/HnixY6QVeKSm+0anUuoMs2SrKBY0tbRUVM\nQBObqdsAdU6XOY0aZ3EJLf/JH8YfcdMY+VGdIgrb2m0uVFK/JM4VXeACk1JwIhUp1y0DFjQxAu/9\n8T1XrrWF3u+P+733fp6P5Jue7+d7fnzOp/ec1/ec8/ncm6pCktSeYyZdAUnSZBgAktQoA0CSGmUA\nSFKjDABJapQBIEmNesoASHJ5kpkkt80pW5Nkd5L9Sa5PsnrOZ59IcneS6SSnjavikqThHM0VwJXA\nqw8p2wrcUFWnAHuAiwGSvAb4tar6deAdwKdHWFdJ0gg9ZQBU1TeABw8pPh/Y0U3v6N7Pln+uW+4m\nYHWStaOpqiRplAZ9BnByVc0AVNUDwMld+XOBH8yZ74ddmSRpkRn1Q+AcpszfNSFJi9DKAZebSbK2\nqmaSTAE/6srvA543Z751wP2HW0ESg0GSBlBVh/uyPW9HewUQfvHb/S7gom76ImDnnPILAJKcCTw0\ne6vocKrKVxXbtm2beB0Wy8u2sC1siyd/jdJTXgEk+SKwCXhmkgPANuDDwFeSvBU4AGzpTuhfTXJu\nku8CPw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y9zj4ef7XFWPAQ8nOYll0hbAR4EP0A2KSPJM4MFG26KA65N8O8mfdmVj\nP0Ym8fcA5jVQrBGHtsnsqKRl01ZJnk7/m9t7quqRJxkHsqzboju5bUjyq8A/AC853Gzdv0fa5yXf\nFkleC8xU1XSSTbPF/PK+Lfu26PxeVT2Q5NnA7iT7OfJ+jOwYmcQVwH3A8+e8XwfcP4F6TMJMd6lG\nkingR135fcDz5sw32ybLoq26B3nXAp+vqp1dcZNtMauq/g+4ETgTODH9X6IIv7hfP2+LbnzN6qp6\nkCO30VJyFnBeku8BV9O/pfMx+rczWmuL2W/4VNV/A/9I/zbW2I+RSQTAt4EXJ3lBkuOANwK7JlCP\nhXDoN5pdwEXd9EXAzjnlF8DPR1I/1F36XQ+8MsnqJGuAV3ZlS80VwB1V9fE5Zc21RZJnzfbkSPI0\n4GzgDvq/AnVLN9uF/GJbXNhNbwH2zCl/Y9cz5oXAi+kPuFwyqupDVfX8qnoR/XPAnqr6YxpsiyTH\nd1fIJDkBeBVwOwtxjEzoifc59HuD3A1snfQT+DHt4xfpp+9PgQPAW+g/pb+h2/evASfOmf+T9Hsw\n3AqcPqf8oq6d7gIumPR+DdAOZwGP0e/tdQtwc/f/f1KDbfGb3f5PA7cBf92VvxC4qduva4Bju/JV\nwJe7fd4LrJ+zrou7NtoHvGrS+zZku2zkiV5AzbVFt8+zx8fts+fEhThGHAgmSY3yT0JKUqMMAElq\nlAEgSY0yACSpUQaAJDXKAJCkRhkAktQoA0CSGvX/0TRMYeLaA00AAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f8c49a41390>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "c = 1\n",
    "incorrect = filter(lambda (x,y,q,r,rv): not rv and y == c, train)\n",
    "print len(incorrect)\n",
    "dists = map(lambda (x,y,q,r,rv): distance(r, c), incorrect)\n",
    "dists.sort()\n",
    "plt.hist(dists, bins=24);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[40.0,\n",
       " 45.254833995939045,\n",
       " 45.254833995939045,\n",
       " 45.254833995939045,\n",
       " 45.254833995939045,\n",
       " 45.254833995939045,\n",
       " 45.254833995939045,\n",
       " 45.254833995939045,\n",
       " 45.254833995939045,\n",
       " 45.254833995939045,\n",
       " 45.254833995939045,\n",
       " 45.254833995939045,\n",
       " 45.254833995939045,\n",
       " 45.254833995939045,\n",
       " 45.254833995939045,\n",
       " 45.254833995939045,\n",
       " 45.254833995939045,\n",
       " 45.254833995939045,\n",
       " 45.254833995939045,\n",
       " 45.254833995939045]"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dists[:20]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "11624\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[1017, 757, 1939, 1002, 597, 1449, 1495, 796, 1478, 1094]"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYAAAAEACAYAAAC6d6FnAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAD3dJREFUeJzt3W2MXFd9x/HvD1wwELAt5NgiBqdpKKWVaGqp4AIVG0HA\nBLWpKkUKRQpOFAmppKBWqmJ4Y6f0BUGiVVBbIUQAB5HyELWKK0XYipJ5kUpNSIibUOfBCAXbSb0B\nSoDwpAD/vphrmCy72fXu+t6xz/cjjXzn7J17/vfueH5zzp27k6pCktSe5wxdgCRpGAaAJDXKAJCk\nRhkAktQoA0CSGmUASFKjFg2AJFuS3J7kUJIHkryva9+Q5ECSh5PsT7Ju4jEfS3I4ycEkF0y0vzvJ\nI91jLj81uyRJWoosdh1Aks3A5qo6mOQs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N\nTqEmeRnwV8C2qnoN4+nsy4atqlefZvxaOWkXcFtVvQq4HfjAYhuZmgDAi8R+qaqOV9XBbvkpxv/J\nm71eIskW4GLgk0PXMqQkLwb+uKo+DVBVP6uq7w9c1pCeC7woyRrghcDjA9fTm6q6E/junOZLgL3d\n8l7gzxbbzjQFgBeJzSPJucAFwF3DVjKofwT+lnmuGWnMecC3k3y6mw77RJIXDF3UEKrqceCjwBHg\nMeDJqrpt2KoGd3ZVzcL4TSSwcbEHTFMALOkisZYkOQu4GXh/NxJoTpJ3ALPdiCjM/zxpxRpgG/DP\nVbUN+BHjYX9zkqxn/I53K/Ay4KwkfzFsVaefaQqAY8ArJu5voaEh3VzdsPZm4LNVdcvQ9QzoDcCf\nJvkG8K/AhUluHLimoRwDjlbVPd39mxkHQoveAnyjqv6vqn4O/Bvw+oFrGtpskk0ASTYDTyz2gGkK\ngK8A5yfZ2p3Nvwxo+RMfnwIOVdX1QxcypKr6YFW9oqrOY/ycuL2qLh+6riF0w/ujSX67a3oz7Z4Y\nPwJsT7I2SRgfi9ZOiM8dEe8DdnbL7wYWfePY998CWpAXif1KkjcA7wIeSHIf46mwD1bVl4etTFPg\nfcDnkvwG8A3gioHrGURV3Z3kZuA+4Onu308MW1V/ktwEzAAvTXIE2A18GPhSkisZB+Sli27HC8Ek\nqU3TNAUkSeqRASBJjTIAJKlRBoAkNcoAkKRGGQCS1CgDQJIaZQBIUqP+H5oJRSflQaeGAAAAAElF\nTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f8c450274d0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "c = 1\n",
    "train = filter(lambda (x,y,q,r,rv): y != c or (y == c and (rv or (not rv and (distance(r, c) < 46.)))), train)\n",
    "print len(train)\n",
    "TRAIN_CLASSES = map(int, plt.hist(zip(*train)[1])[0])\n",
    "TRAIN_CLASSES"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### class 3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "175\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYAAAAEACAYAAAC6d6FnAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAEyNJREFUeJzt3V2wZWV95/HvDxpQfGnACd2lrbTEATVVI8NUAqOT8USI\ntKQGzAUTdVK2kotUoq3RmmijF3RfCTqWCZWXKSuEaR3FCEwCVeMMhIKdKqfSGAtaEDpIBrV5GQ7l\nCFQlU2XE/s/FWqezac+hT++99tmHfr6fql299rPWXut/nrP3/q1nvZxOVSFJas9x8y5AkjQfBoAk\nNcoAkKRGGQCS1CgDQJIaZQBIUqOOGABJrk2ymOTesbZPJ9mfZF+Sm5K8fGzeFUke6ue/fVaFS5Km\ns5oRwHXARYe13Qb8XFWdAzwEXAGQ5I3AvwfeALwD+KMkGa5cSdJQjhgAVfV14KnD2m6vqoP9073A\nln76EuArVfVsVX2PLhx+YbhyJUlDGeIcwOXA1/rpVwGPjM17rG+TJK0zUwVAkk8CP66q65eallnM\nvzUhSevQhklfmGQ7cDHwtrHmR4FXjz3fAjy+wusNBkmaQFUNcm51tSOAMLZ3n2Qb8DHgkqr60dhy\ntwDvSnJiktcCrwO+sdJKq+o5j/POuwj4H3SDhtU9Tjrpg1xzzTU/ta5JHldeeeUg6xn6sR7rsiZr\naqGu9VjTkI44AkjyZWABeEWSA8CVwCeAE4G/7C/y2VtVv11VDyT5KvAA8GPgt2voiiVJgzhiAFTV\ne5Zpvu55lv8U8KlpipIkzZ53Ao9ZWFiYdwnLWo91WdPqWNPqrce61mNNQ8q8jtAk+amjQ+efv427\n7vodYNuq13PSSTv4zGfOYseOHQNXKEnrTxJqjU8CS5KOMQaAJDXKAJCkRhkAktQoA0CSGmUASFKj\nDABJapQBIEmNMgAkqVEGgCQ1ygCQp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\nvl1Vm6vqzKp6Ld0X1r+sqieZYz8Bf0F/jqh/z59YVf+3r+nX1qiflqvrsSRv7eu6gO4cBAzZV9Oc\nuZ7ijPc2uitwHgJ2ruF23wL8hO6s/T10x5C3AacBt/c1/SXdcHDpNX9Ad8b/W8C5M67vrfzTVUCv\nBe4CvkN3pcsJfftJwFf7vtsLbJ1RLW+ie6Pvo9s72jjvfqI7dLAfuJfuROsJ8+gn4Mt0e1Y/ogum\n99NdgXFUfUMXFA/1tb93BjU9BHy/f5/fTX9VVL/8FX1N++mvNOnbB/tsLlfTYfMfpr8KaM79tAH4\nInAf8E3grWvZT89T15v7eu4B/pouLAftK28Ek6RG+V9CSlKjDABJapQBIEmNMgAkqVEGgCQ1ygCQ\npEYZAJLUKANAkhr1/wG7eGpHl5M12QAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f8c4741ad90>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "c = 3\n",
    "incorrect = filter(lambda (x,y,q,r,rv): not rv and y == c, train)\n",
    "print len(incorrect)\n",
    "dists = map(lambda (x,y,q,r,rv): distance(r, c), incorrect)\n",
    "dists.sort()\n",
    "plt.hist(dists, bins=24);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[30.0,\n",
       " 30.0,\n",
       " 30.0,\n",
       " 30.0,\n",
       " 30.0,\n",
       " 30.0,\n",
       " 30.0,\n",
       " 30.0,\n",
       " 30.0,\n",
       " 30.0,\n",
       " 30.0,\n",
       " 30.0,\n",
       " 30.0,\n",
       " 30.0,\n",
       " 30.0,\n",
       " 30.0,\n",
       " 30.0,\n",
       " 30.0,\n",
       " 30.0,\n",
       " 35.777087639996637,\n",
       " 185.77674773770801,\n",
       " 282.85155117128136,\n",
       " 316.42534664593478,\n",
       " 329.13371143047624,\n",
       " 338.00147928670373,\n",
       " 364.9438312946254,\n",
       " 403.27162062312294,\n",
       " 416.20307543313515,\n",
       " 430.83639586274512,\n",
       " 449.44410108488466]"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dists[100:130]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "11449\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[1017, 757, 1939, 827, 597, 1449, 1495, 796, 1478, 1094]"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYAAAAEACAYAAAC6d6FnAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAD4BJREFUeJzt3W+MXFd9xvHvAy4xELAt5KxFDE7TUEor0dRSwQUqNoKA\nCWpTVYoUihScKBJSSUGtVMXwxk7pC4JEq6C2QogADiINELWKK0XYipJ9QaUmJMRNqPPHCAXbSb0B\nSoDwTwF+fTHXMN7sZte763vHPt+PNPKds3fu+c3d8Txzzr13NlWFJKk9zxu6AEnSMAwASWqUASBJ\njTIAJKlRBoAkNcoAkKRGLRoASTYnuTPJwSQPJnl/174hyf4kjyTZl2Td2GM+nuRQkgNJLhxrf0+S\nR7vHXHFqnpIkaSmy2HUASTYBm6rqQJKzgfuAS4Erge9W1UeTXAtsqKqdSd4BXFNV70zyeuCGqtqW\nZANwL7AVSLedrVX1/VP39CRJC1l0BFBVx6rqQLf8NPAQsJlRCOzpVtvT3af796Zu/buBdUmmgLcD\n+6vq+1X1FLAf2L6Kz0WSdBJO6hhAkvOAC4H/AqaqahZGIQGc0612LnBk7GFHu7a57Y93bZKkASw5\nALrpn1uBD3QjgYXmjjLP/ZqnnefYhiTpFFuzlJWSrGH05v+5qrqta55NMlVVs91xgie79qPAK8Ye\nvhl4omufntN+1zx9GQqStAxVNd8H7QUtdQTwaeBgV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bgU+0I0EmpPkncBsNyIK\n879OWrEG2Ar8c1VtBX7MaNjfnCTrGX3i3QK8HDg7yV8MW9XpZ5IC4CjwyrH7m2loSDdXN6y9Ffhc\nVd02dD0DeiPwp0m+CfwrcFGSmwauaShHgSNVdW93/1ZGgdCitwLfrKr/q6pfAP8GvGHgmoY2m2QK\nIMkm4MnFHjBJAfBV4IIkW7qj+ZcDLZ/x8WngYFXdMHQhQ6qqD1XVK6vqfEaviTur6oqh6xpCN7w/\nkuS3u6a30O6B8cPAtiRrk4TRvmjtgPjcEfFeYEe3/B5g0Q+OfX8X0IK8SOzXkrwReDfwYJL7GU2F\nfaiqvjxsZZoA7wc+n+Q3gG8CVw5czyCq6p4ktwL3A890/35y2Kr6k+RmYBp4WZLDwC7gI8CXklzF\nKCAvW3Q7XggmSW2apCkgSVKPDABJapQBIEmNMgAkqVEGgCQ1ygCQpEYZAJLUKANAkhr1/7vbRCvP\nDetxAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f8c462be350>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "c = 3\n",
    "train = filter(lambda (x,y,q,r,rv): y != c or (y == c and (rv or (not rv and (distance(r, c) < 1.)))), train)\n",
    "print len(train)\n",
    "TRAIN_CLASSES = map(int, plt.hist(zip(*train)[1])[0])\n",
    "TRAIN_CLASSES"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.6921093347086127"
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "M = max(TRAIN_CLASSES)\n",
    "m = min(TRAIN_CLASSES)\n",
    "(M - m) / float(M)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "11449"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(train)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## NEW: filter using EXIF"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "a28625b1b71f42f598b13de2b15b6554",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "A Jupyter Widget"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    }
   ],
   "source": [
    "train_with_exif = []\n",
    "for x,y,q,r,rv in progress_iter(train, True):\n",
    "    tags = exifread.process_file(open(x, 'rb'))\n",
    "    train_with_exif.append((x,y,q,r,rv,tags))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "train = train_with_exif"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Lens Make'"
      ]
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Image Make'\n",
    "'Image Model'\n",
    "'Lens Make'\n",
    "# distance((int(str(t['EXIF ExifImageWidth'])), int(str(t['EXIF ExifImageLength']))), c) > 0.1\n",
    "# 'Image Orientation'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### class 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1017\n"
     ]
    }
   ],
   "source": [
    "c = 0\n",
    "c_train = filter(lambda (x,y,q,r,rv,tags): y == c, train)\n",
    "print len(c_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Horizontal (normal)'"
      ]
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "str(c_train[0][5]['Image Orientation'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "994\n"
     ]
    }
   ],
   "source": [
    "c1 = lambda t: 'EXIF ExifImageWidth' in t\n",
    "c2 = lambda t: 'EXIF ExifImageLength' in t\n",
    "c3 = lambda t: distance((int(str(t['EXIF ExifImageWidth'])), int(str(t['EXIF ExifImageLength']))), c) < 0.1\n",
    "cond = [\n",
    "    lambda t: str(t['Image Make']) == 'HTC',\n",
    "    lambda t: str(t['Image Model']) == 'HTC One',\n",
    "    lambda t: c1(t) and c2(t) and c3(t),\n",
    "    lambda t: 'Image Orientation' in t and str(t['Image Orientation']) == 'Horizontal (normal)'\n",
    "]\n",
    "all_cond = lambda (x,y,q,r,rv,t): all(map(lambda c: c(t), cond))\n",
    "print len(filter(all_cond, c_train))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "11449\n",
      "11426\n"
     ]
    }
   ],
   "source": [
    "print len(train)\n",
    "train = filter(lambda (x,y,q,r,rv,tags): y != c or all_cond((x,y,q,r,rv,tags)), train)\n",
    "print len(train)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### class 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "757\n"
     ]
    }
   ],
   "source": [
    "c = 1\n",
    "c_train = filter(lambda (x,y,q,r,rv,tags): y == c, train)\n",
    "print len(c_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "662\n"
     ]
    }
   ],
   "source": [
    "c1 = lambda t: 'EXIF ExifImageWidth' in t\n",
    "c2 = lambda t: 'EXIF ExifImageLength' in t\n",
    "c3 = lambda t: distance((int(str(t['EXIF ExifImageWidth'])), int(str(t['EXIF ExifImageLength']))), c) < 0.1\n",
    "cond = [\n",
    "    lambda t: 'Image Make' in t and str(t['Image Make']) == 'LGE',\n",
    "    lambda t: 'Image Model' in t and str(t['Image Model']) == 'Nexus 5X',\n",
    "    lambda t: c1(t) and c2(t) and c3(t),\n",
    "#     lambda t: 'Image Orientation' in t and str(t['Image Orientation']) == 'Horizontal (normal)'\n",
    "]\n",
    "all_cond = lambda (x,y,q,r,rv,t): all(map(lambda c: c(t), cond))\n",
    "print len(filter(all_cond, c_train))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "11426\n",
      "11331\n"
     ]
    }
   ],
   "source": [
    "print len(train)\n",
    "train = filter(lambda (x,y,q,r,rv,tags): y != c or all_cond((x,y,q,r,rv,tags)), train)\n",
    "print len(train)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### class 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1939\n"
     ]
    }
   ],
   "source": [
    "c = 2\n",
    "c_train = filter(lambda (x,y,q,r,rv,tags): y == c, train)\n",
    "print len(c_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['XT1080']\n"
     ]
    }
   ],
   "source": [
    "print list(set([str(t['Image Model']) for x,y,q,r,rv,t in c_train if 'data/train' in x]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "801\n"
     ]
    }
   ],
   "source": [
    "c1 = lambda t: 'EXIF ExifImageWidth' in t\n",
    "c2 = lambda t: 'EXIF ExifImageLength' in t\n",
    "c3 = lambda t: distance((float(str(t['EXIF ExifImageWidth'])), float(str(t['EXIF ExifImageLength']))), c) < 0.1\n",
    "cond = [\n",
    "    lambda t: 'Image Make' in t and str(t['Image Make']) == 'Motorola',\n",
    "    lambda t: 'Image Model' in t and str(t['Image Model']) == 'XT1080',\n",
    "    lambda t: c1(t) and c2(t) and c3(t),\n",
    "#     lambda t: 'Image Orientation' in t and str(t['Image Orientation']) == 'Horizontal (normal)'\n",
    "]\n",
    "all_cond = lambda (x,y,q,r,rv,t): all(map(lambda c: c(t), cond))\n",
    "print len(filter(all_cond, c_train))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "11331\n",
      "10193\n"
     ]
    }
   ],
   "source": [
    "print len(train)\n",
    "train = filter(lambda (x,y,q,r,rv,tags): y != c or all_cond((x,y,q,r,rv,tags)), train)\n",
    "print len(train)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### class 3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "827\n"
     ]
    }
   ],
   "source": [
    "c = 3\n",
    "c_train = filter(lambda (x,y,q,r,rv,tags): y == c, train)\n",
    "print len(c_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['motorola']\n"
     ]
    }
   ],
   "source": [
    "print list(set([str(t['Image Make']) for x,y,q,r,rv,t in c_train if 'data/train' in x]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Nexus 6']\n"
     ]
    }
   ],
   "source": [
    "print list(set([str(t['Image Model']) for x,y,q,r,rv,t in c_train if 'data/train' in x]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "793\n"
     ]
    }
   ],
   "source": [
    "c1 = lambda t: 'EXIF ExifImageWidth' in t\n",
    "c2 = lambda t: 'EXIF ExifImageLength' in t\n",
    "c3 = lambda t: distance((float(str(t['EXIF ExifImageWidth'])), float(str(t['EXIF ExifImageLength']))), c) < 0.1\n",
    "cond = [\n",
    "    lambda t: 'Image Make' in t and str(t['Image Make']) == 'motorola',\n",
    "    lambda t: 'Image Model' in t and str(t['Image Model']) == 'Nexus 6',\n",
    "    lambda t: c1(t) and c2(t) and c3(t),\n",
    "#     lambda t: 'Image Orientation' in t and str(t['Image Orientation']) == 'Horizontal (normal)'\n",
    "]\n",
    "all_cond = lambda (x,y,q,r,rv,t): all(map(lambda c: c(t), cond))\n",
    "print len(filter(all_cond, c_train))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10193\n",
      "10159\n"
     ]
    }
   ],
   "source": [
    "print len(train)\n",
    "train = filter(lambda (x,y,q,r,rv,tags): y != c or all_cond((x,y,q,r,rv,tags)), train)\n",
    "print len(train)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### class 4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "597\n"
     ]
    }
   ],
   "source": [
    "c = 4\n",
    "c_train = filter(lambda (x,y,q,r,rv,tags): y == c, train)\n",
    "print len(c_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Motorola']\n"
     ]
    }
   ],
   "source": [
    "print list(set([str(t['Image Make']) for x,y,q,r,rv,t in c_train if 'data/train' in x]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['XT1096']\n"
     ]
    }
   ],
   "source": [
    "print list(set([str(t['Image Model']) for x,y,q,r,rv,t in c_train if 'data/train' in x]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "595\n"
     ]
    }
   ],
   "source": [
    "c1 = lambda t: 'EXIF ExifImageWidth' in t\n",
    "c2 = lambda t: 'EXIF ExifImageLength' in t\n",
    "c3 = lambda t: distance((float(str(t['EXIF ExifImageWidth'])), float(str(t['EXIF ExifImageLength']))), c) < 0.1\n",
    "cond = [\n",
    "    lambda t: 'Image Make' in t and str(t['Image Make']) == 'Motorola',\n",
    "    lambda t: 'Image Model' in t and str(t['Image Model']) == 'XT1096',\n",
    "    lambda t: c1(t) and c2(t) and c3(t),\n",
    "#     lambda t: 'Image Orientation' in t and str(t['Image Orientation']) == 'Horizontal (normal)'\n",
    "]\n",
    "all_cond = lambda (x,y,q,r,rv,t): all(map(lambda c: c(t), cond))\n",
    "print len(filter(all_cond, c_train))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 96,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10159\n",
      "10157\n"
     ]
    }
   ],
   "source": [
    "print len(train)\n",
    "train = filter(lambda (x,y,q,r,rv,tags): y != c or all_cond((x,y,q,r,rv,tags)), train)\n",
    "print len(train)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### class 5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1449\n"
     ]
    }
   ],
   "source": [
    "c = 5\n",
    "c_train = filter(lambda (x,y,q,r,rv,tags): y == c, train)\n",
    "print len(c_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['samsung', 'SAMSUNG']\n",
      "['SAMSUNG-SM-N900A']\n"
     ]
    }
   ],
   "source": [
    "print list(set([str(t['Image Make']) for x,y,q,r,rv,t in c_train if 'data/train' in x]))\n",
    "print list(set([str(t['Image Model']) for x,y,q,r,rv,t in c_train if 'data/train' in x]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['SAMSUNG-SM-N900A', 'SM-N9005']\n"
     ]
    }
   ],
   "source": [
    "print list(set([str(t['Image Model']) for x,y,q,r,rv,t in c_train]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['[4601, 0]', '2322', '[3264, 0]', '4128', '3210', '3399', '3142', '3264', '1836']\n"
     ]
    }
   ],
   "source": [
    "print list(set([str(t['EXIF ExifImageWidth']) for x,y,q,r,rv,t in c_train]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def f(v):\n",
    "    return float(str(v).replace(', 0]', '').replace('[', ''))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 102,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "903\n"
     ]
    }
   ],
   "source": [
    "c1 = lambda t: 'EXIF ExifImageWidth' in t\n",
    "c2 = lambda t: 'EXIF ExifImageLength' in t\n",
    "c3 = lambda t: distance((f(t['EXIF ExifImageWidth']), f(t['EXIF ExifImageLength'])), c) < 0.1\n",
    "cond = [\n",
    "    lambda t: 'Image Make' in t and str(t['Image Make']).lower() == 'samsung',\n",
    "    lambda t: 'Image Model' in t and str(t['Image Model']) in ['SAMSUNG-SM-N900A', 'SM-N9005'],\n",
    "    lambda t: c1(t) and c2(t) and c3(t),\n",
    "#     lambda t: 'Image Orientation' in t and str(t['Image Orientation']) == 'Horizontal (normal)'\n",
    "]\n",
    "all_cond = lambda (x,y,q,r,rv,t): all(map(lambda c: c(t), cond))\n",
    "print len(filter(all_cond, c_train))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 103,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10157\n",
      "9611\n"
     ]
    }
   ],
   "source": [
    "print len(train)\n",
    "train = filter(lambda (x,y,q,r,rv,tags): y != c or all_cond((x,y,q,r,rv,tags)), train)\n",
    "print len(train)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### class 6"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 104,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1495\n"
     ]
    }
   ],
   "source": [
    "c = 6\n",
    "c_train = filter(lambda (x,y,q,r,rv,tags): y == c, train)\n",
    "print len(c_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 105,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['samsung']\n",
      "['SCH-I545']\n"
     ]
    }
   ],
   "source": [
    "print list(set([str(t['Image Make']) for x,y,q,r,rv,t in c_train if 'data/train' in x]))\n",
    "print list(set([str(t['Image Model']) for x,y,q,r,rv,t in c_train if 'data/train' in x]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 106,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['GT-I9505', 'SCH-I545', 'None', 'GT-I9500']\n"
     ]
    }
   ],
   "source": [
    "print list(set([str(t.get('Image Model', None)) for x,y,q,r,rv,t in c_train]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 107,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1493\n"
     ]
    }
   ],
   "source": [
    "c1 = lambda t: 'EXIF ExifImageWidth' in t\n",
    "c2 = lambda t: 'EXIF ExifImageLength' in t\n",
    "c3 = lambda t: distance((f(t['EXIF ExifImageWidth']), f(t['EXIF ExifImageLength'])), c) < 0.1\n",
    "cond = [\n",
    "    lambda t: 'Image Make' in t and str(t['Image Make']).lower() == 'samsung',\n",
    "    lambda t: 'Image Model' in t and str(t['Image Model']) in ['GT-I9505', 'SCH-I545', 'GT-I9500'],\n",
    "    lambda t: c1(t) and c2(t) and c3(t),\n",
    "#     lambda t: 'Image Orientation' in t and str(t['Image Orientation']) == 'Horizontal (normal)'\n",
    "]\n",
    "all_cond = lambda (x,y,q,r,rv,t): all(map(lambda c: c(t), cond))\n",
    "print len(filter(all_cond, c_train))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 108,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "9611\n",
      "9609\n"
     ]
    }
   ],
   "source": [
    "print len(train)\n",
    "train = filter(lambda (x,y,q,r,rv,tags): y != c or all_cond((x,y,q,r,rv,tags)), train)\n",
    "print len(train)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### class 7"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 109,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "796\n"
     ]
    }
   ],
   "source": [
    "c = 7\n",
    "c_train = filter(lambda (x,y,q,r,rv,tags): y == c, train)\n",
    "print len(c_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 110,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['SONY']\n",
      "['NEX-7']\n"
     ]
    }
   ],
   "source": [
    "print list(set([str(t['Image Make']) for x,y,q,r,rv,t in c_train if 'data/train' in x]))\n",
    "print list(set([str(t['Image Model']) for x,y,q,r,rv,t in c_train if 'data/train' in x]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 111,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "757\n"
     ]
    }
   ],
   "source": [
    "c1 = lambda t: 'EXIF ExifImageWidth' in t\n",
    "c2 = lambda t: 'EXIF ExifImageLength' in t\n",
    "c3 = lambda t: distance((f(t['EXIF ExifImageWidth']), f(t['EXIF ExifImageLength'])), c) < 0.1\n",
    "cond = [\n",
    "    lambda t: 'Image Make' in t and str(t['Image Make']) == 'SONY',\n",
    "    lambda t: 'Image Model' in t and str(t['Image Model']) == 'NEX-7',\n",
    "    lambda t: c1(t) and c2(t) and c3(t),\n",
    "#     lambda t: 'Image Orientation' in t and str(t['Image Orientation']) == 'Horizontal (normal)'\n",
    "]\n",
    "all_cond = lambda (x,y,q,r,rv,t): all(map(lambda c: c(t), cond))\n",
    "print len(filter(all_cond, c_train))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 112,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "9609\n",
      "9570\n"
     ]
    }
   ],
   "source": [
    "print len(train)\n",
    "train = filter(lambda (x,y,q,r,rv,tags): y != c or all_cond((x,y,q,r,rv,tags)), train)\n",
    "print len(train)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### class 8"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 113,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1478\n"
     ]
    }
   ],
   "source": [
    "c = 8\n",
    "c_train = filter(lambda (x,y,q,r,rv,tags): y == c, train)\n",
    "print len(c_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 114,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Apple']\n",
      "['iPhone 4S']\n",
      "['Apple']\n",
      "['iPhone 4S back camera 4.28mm f/2.4']\n"
     ]
    }
   ],
   "source": [
    "print list(set([str(t['Image Make']) for x,y,q,r,rv,t in c_train if 'data/train' in x]))\n",
    "print list(set([str(t['Image Model']) for x,y,q,r,rv,t in c_train if 'data/train' in x]))\n",
    "print list(set([str(t['EXIF LensMake']) for x,y,q,r,rv,t in c_train if 'data/train' in x]))\n",
    "print list(set([str(t['EXIF LensModel']) for x,y,q,r,rv,t in c_train if 'data/train' in x]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 115,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "888\n"
     ]
    }
   ],
   "source": [
    "c1 = lambda t: 'EXIF ExifImageWidth' in t\n",
    "c2 = lambda t: 'EXIF ExifImageLength' in t\n",
    "c3 = lambda t: distance((f(t['EXIF ExifImageWidth']), f(t['EXIF ExifImageLength'])), c) < 0.1\n",
    "cond = [\n",
    "    lambda t: 'Image Make' in t and str(t['Image Make']) == 'Apple',\n",
    "    lambda t: 'Image Model' in t and str(t['Image Model']) == 'iPhone 4S',\n",
    "    lambda t: 'EXIF LensMake' in t and str(t['EXIF LensMake']) == 'Apple',\n",
    "    lambda t: 'EXIF LensModel' in t and str(t['EXIF LensModel']) == 'iPhone 4S back camera 4.28mm f/2.4',\n",
    "    lambda t: c1(t) and c2(t) and c3(t),\n",
    "#     lambda t: 'Image Orientation' in t and str(t['Image Orientation']) == 'Horizontal (normal)'\n",
    "]\n",
    "all_cond = lambda (x,y,q,r,rv,t): all(map(lambda c: c(t), cond))\n",
    "print len(filter(all_cond, c_train))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 116,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "9570\n",
      "8980\n"
     ]
    }
   ],
   "source": [
    "print len(train)\n",
    "train = filter(lambda (x,y,q,r,rv,tags): y != c or all_cond((x,y,q,r,rv,tags)), train)\n",
    "print len(train)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### class 9"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 117,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1094\n"
     ]
    }
   ],
   "source": [
    "c = 9\n",
    "c_train = filter(lambda (x,y,q,r,rv,tags): y == c, train)\n",
    "print len(c_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 118,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Apple']\n",
      "['iPhone 6']\n",
      "['Apple']\n",
      "['iPhone 6 back camera 4.15mm f/2.2']\n"
     ]
    }
   ],
   "source": [
    "print list(set([str(t['Image Make']) for x,y,q,r,rv,t in c_train if 'data/train' in x]))\n",
    "print list(set([str(t['Image Model']) for x,y,q,r,rv,t in c_train if 'data/train' in x]))\n",
    "print list(set([str(t['EXIF LensMake']) for x,y,q,r,rv,t in c_train if 'data/train' in x]))\n",
    "print list(set([str(t['EXIF LensModel']) for x,y,q,r,rv,t in c_train if 'data/train' in x]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 119,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1081\n"
     ]
    }
   ],
   "source": [
    "c1 = lambda t: 'EXIF ExifImageWidth' in t\n",
    "c2 = lambda t: 'EXIF ExifImageLength' in t\n",
    "c3 = lambda t: distance((f(t['EXIF ExifImageWidth']), f(t['EXIF ExifImageLength'])), c) < 0.1\n",
    "cond = [\n",
    "    lambda t: 'Image Make' in t and str(t['Image Make']) == 'Apple',\n",
    "    lambda t: 'Image Model' in t and str(t['Image Model']) == 'iPhone 6',\n",
    "    lambda t: 'EXIF LensMake' in t and str(t['EXIF LensMake']) == 'Apple',\n",
    "    lambda t: 'EXIF LensModel' in t and str(t['EXIF LensModel']) == 'iPhone 6 back camera 4.15mm f/2.2',\n",
    "    lambda t: c1(t) and c2(t) and c3(t),\n",
    "#     lambda t: 'Image Orientation' in t and str(t['Image Orientation']) == 'Horizontal (normal)'\n",
    "]\n",
    "all_cond = lambda (x,y,q,r,rv,t): all(map(lambda c: c(t), cond))\n",
    "print len(filter(all_cond, c_train))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 120,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "8980\n",
      "8967\n"
     ]
    }
   ],
   "source": [
    "print len(train)\n",
    "train = filter(lambda (x,y,q,r,rv,tags): y != c or all_cond((x,y,q,r,rv,tags)), train)\n",
    "print len(train)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### TODO: finally fill validation set up from filtered train (q $\\geq$ 95)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 121,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[48, 48, 48, 48, 48, 48, 48, 48, 48, 48]"
      ]
     },
     "execution_count": 121,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAEACAYAAACj0I2EAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAADWVJREFUeJzt3X2sZHV9x/H3Z7mtiihSi0vpRohpRG1ikT8ANU3WSn1M\nC8bQ4EOKD/3PFlIS4sI/kDRpIMEYkzZtjJSs1gcUH6CJKZSsQ2IbfIhQtoWuTZEipXspUTTEtHLd\nb/+4s/G6ubszc++dOZfvfb+SCWfOzpnfNxN4c+bceyBVhSTp2W/X0ANIkraGQZekJgy6JDVh0CWp\nCYMuSU0YdElqYmmaFyV5BPgRcAR4pqrOT3IacCtwFvAI8AdV9aM5zSlJmmDaM/QjwN6qek1VnT/e\ntw+4u6rOAQ4A18xjQEnSdKYNetZ57cXA/vH2fuCSrRpKkjS7aYNewJ1JvpXkj8b7dlfVMkBVHQZO\nn8eAkqTpTHUNHXhdVR1OcjpwV5JDrEZekrRNTBX08Rk4VfU/Sb4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text/plain": [
       "<matplotlib.figure.Figure at 0x7f8c29440cd0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "RNG(seed=777).shuffle(train)\n",
    "new_train = []\n",
    "for x,y,q,r,rv,_ in train:\n",
    "    VAL_CLASSES = np.bincount(zip(*val)[1])\n",
    "    if q >= 95 and VAL_CLASSES[y] < N_VAL_PER_CLASS:\n",
    "        val.append((x, y))\n",
    "    else:\n",
    "        new_train.append((x,y,q,r,rv))\n",
    "\n",
    "train = new_train\n",
    "        \n",
    "VAL_CLASSES = map(int, plt.hist(zip(*val)[1])[0])\n",
    "VAL_CLASSES"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 122,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.692109334709\n",
      "8847\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[991, 651, 767, 773, 595, 873, 1490, 751, 888, 1068]"
      ]
     },
     "execution_count": 122,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYAAAAEACAYAAAC6d6FnAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAFIBJREFUeJzt3XvMXPV95/H3B1xiSogDxGDFLjhcQ6KliCqJs2m3T0ob\nLlHj/FF2SbeFkGg3uyGXFm02QKXaVbXbECnKRemKjeoiU4WQQKriSAhcBKMKbYAgQqAxF0dpsA3B\nLQnOboJAXL77xxwnw9Pn4bFn7DmP/Xu/pJHP+c7vnN9vxvZ8zmXOmVQVkqT2HNL3ACRJ/TAAJKlR\nBoAkNcoAkKRGGQCS1CgDQJIatWAAJNmQZGeSB2bVP5rk4SQPJvnUSP2KJFuTPJTkXSP1c7v2jyb5\n5L59GZKkvZWFrgNI8uvAT4Frq+qMrjYDXAmcX1UvJHldVT2V5HTgOuAtwCrgNuAUIMCjwNnAE8C3\ngAur6uH98qokSQtaslCDqrozy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9Sb4PfAV4Z5Jrex5TX3YA26vq3m7+RoaB\n0KLfBr5fVT+uqheBvwX+bc9j6tvOJMcBJFkB/PNCCyymAPgWcHKSE7qz+RcCLX/j46+BLVX1+b4H\n0qequrKqjq+qExn+m7i9qi7qe1x96Hbvtyc5tSudTbsnxrcBa5IsTRKG70VrJ8Rn7xFvAt7fTV8M\nLLjhOO17Ac3Li8R+Ick7gP8IPJjk2wwPhV1ZVbf0OzItAh8Dvpzkl4DvA5f0PJ5eVNU9SW4Evg08\n3/35pX5HNT1JrgNmgGOSbAPWAZ8CbkjyAYYBecGC6/FCMElq02I6BCRJmiIDQJIaZQBIUqMMAElq\nlAEgSY0yACSpUQaAJDXKAJCkRv1/5eNZF/MsMAEAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f8c29473d50>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "M = max(TRAIN_CLASSES)\n",
    "m = min(TRAIN_CLASSES)\n",
    "print (M - m) / float(M)\n",
    "print len(train)\n",
    "\n",
    "TRAIN_CLASSES = map(int, plt.hist(zip(*train)[1])[0])\n",
    "TRAIN_CLASSES"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## now need to crop and to save images to disk, but now cleverer:\n",
    "### $\\approx$ undersampling, save separate blocks (of $\\approx$ same size) for each class"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 446,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[21, 14, 16, 16, 12, 18, 31, 16, 18, 22]"
      ]
     },
     "execution_count": 446,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "BLOCK_SIZE = 48\n",
    "N_BLOCKS = [int(np.round(t/float(BLOCK_SIZE))) for t in TRAIN_CLASSES]\n",
    "N_BLOCKS"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "crop_size = 1024\n",
    "for c in xrange(10):\n",
    "    if c == 3:\n",
    "        continue\n",
    "    class_train = filter(lambda (x,y,q,r,rv): y == c, train)\n",
    "    RNG(seed=7331 + c).shuffle(class_train)\n",
    "    class_blocks = []\n",
    "    for _ in xrange(N_BLOCKS[c]):\n",
    "        class_blocks.append([])\n",
    "    pos = 0\n",
    "    for x,_,_,_,_ in progress_iter(class_train, True):\n",
    "        x = Image.open(x)\n",
    "        w = x.size[0]\n",
    "        h = x.size[1]\n",
    "        x = x.crop((w/2-crop_size/2, h/2-crop_size/2,\n",
    "                    w/2+crop_size/2, h/2+crop_size/2))\n",
    "        class_blocks[pos % N_BLOCKS[c]].append(np.asarray(x, dtype=np.uint8))\n",
    "        pos += 1\n",
    "    for b in xrange(N_BLOCKS[c]):\n",
    "        np.save('../data/X_{0}_{1}.npy'.format(c, b), np.asarray(class_blocks[b], dtype=np.uint8))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### save validation set"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 123,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "480"
      ]
     },
     "execution_count": 123,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(val)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 124,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "RNG(seed=9999).shuffle(val)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "y_val = np.asarray(zip(*val)[1])\n",
    "crop_size = c = 1024\n",
    "X_val = np.zeros((len(y_val), crop_size, crop_size, 3), dtype=np.uint8)\n",
    "pos = 0\n",
    "for x, _ in progress_iter(val, True):\n",
    "    x = Image.open(x)\n",
    "    w = x.size[0]\n",
    "    h = x.size[1]\n",
    "    x = x.crop((w/2-c/2, h/2-c/2,\n",
    "                w/2+c/2, h/2+c/2))\n",
    "    X_val[pos] = np.asarray(x, dtype=np.uint8)\n",
    "    pos += 1\n",
    "np.save('../data/X_val.npy', X_val)\n",
    "np.save('../data/y_val.npy', y_val)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### [for pseudo-labels] split validation for training, validation"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "N_VAL_TRAIN_PER_CLASS = 24\n",
    "N_VAL_TRAIN = N_VAL_TRAIN_PER_CLASS * 10\n",
    "D = 1024\n",
    "d = 512\n",
    "X_val_train = np.zeros((N_VAL_TRAIN, D, D, 3), dtype=np.uint8)\n",
    "X_val_val = np.zeros((len(y_val) - N_VAL_TRAIN, d, d, 3), dtype=np.uint8)\n",
    "y_val_train = []\n",
    "y_val_val = []\n",
    "pos_val_train = 0\n",
    "pos_val_val = 0\n",
    "for i in xrange(len(y_val)):\n",
    "    c = y_val[i]\n",
    "    if y_val_train.count(c) < N_VAL_TRAIN_PER_CLASS:\n",
    "        X_val_train[pos_val_train] = X_val[i]\n",
    "        pos_val_train += 1\n",
    "        y_val_train.append(c)\n",
    "    else:\n",
    "        X_val_val[pos_val_val] = X_val[i][D/2-d/2:D/2+d/2, D/2-d/2:D/2+d/2, :]\n",
    "        pos_val_val += 1\n",
    "        y_val_val.append(c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 106,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "np.save('../data/X_val_train.npy', X_val_train)\n",
    "np.save('../data/y_val_train.npy', np.asarray(y_val_train))\n",
    "np.save('../data/X_val_val.npy', X_val_val)\n",
    "np.save('../data/y_val_val.npy', np.asarray(y_val_val))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### [!!!] cyclicly add `X_val_train` to all blocks"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 107,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(240, 1024, 1024, 3)\n"
     ]
    }
   ],
   "source": [
    "X_val_train = np.load('../data/X_val_train.npy')\n",
    "y_val_train = np.load('../data/y_val_train.npy')\n",
    "print X_val_train.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "N_BLOCKS = [21, 16, 16, 17, 12, 19, 31, 16, 31, 23]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 127,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "for c in xrange(10):\n",
    "    print c\n",
    "    c_ind = np.arange(len(y_val_train))[y_val_train == 0]\n",
    "    for block_num, i in enumerate(c_ind):\n",
    "        block_num = block_num % N_BLOCKS[c]\n",
    "        X_block = np.load('X_{0}_{1}.npy'.format(c, block_num))\n",
    "        X_block = np.concatenate((X_block, X_val_train[i].reshape((1, 1024, 1024, 3))))\n",
    "        N_IMAGES_PER_CLASS[c] -= len(X_block)\n",
    "        np.save('X_{0}_{1}.npy'.format(c, block_num), X_block)\n",
    "        \n",
    "print N_IMAGES_PER_CLASS"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### check count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "N_IMAGES_PER_CLASS = [1014, 746, 767, 807, 598, 918, 1492, 790, 1478, 1081]\n",
    "for i in xrange(10):\n",
    "    N_IMAGES_PER_CLASS[i] += 24"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "for c in xrange(10):\n",
    "    for b in xrange(N_BLOCKS[c]):\n",
    "        N_IMAGES_PER_CLASS[c] -= len(np.load('../data/X_{0}_{1}.npy'.format(c, b)))\n",
    "    print c, N_IMAGES_PER_CLASS[c]\n",
    "print N_IMAGES_PER_CLASS"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### generate `N_IMAGES_PER_BLOCK`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "5\n",
      "6\n",
      "7\n",
      "8\n",
      "9\n"
     ]
    }
   ],
   "source": [
    "N_BLOCKS = [21, 14, 16, 16, 12, 18, 31, 16, 18, 22]\n",
    "N_IMAGES_PER_BLOCK = []\n",
    "for c in xrange(10):\n",
    "    print c\n",
    "    N_IMAGES_PER_BLOCK.append([])\n",
    "    for b in xrange(N_BLOCKS[c]):\n",
    "        N_IMAGES_PER_BLOCK[c].append(len(np.load('../data/X_{0}_{1}.npy'.format(c, b))))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.12"
  },
  "latex_envs": {
   "LaTeX_envs_menu_present": true,
   "autocomplete": true,
   "bibliofile": "biblio.bib",
   "cite_by": "apalike",
   "current_citInitial": 1,
   "eqLabelWithNumbers": true,
   "eqNumInitial": 1,
   "hotkeys": {
    "equation": "Ctrl-E",
    "itemize": "Ctrl-I"
   },
   "labels_anchors": false,
   "latex_user_defs": false,
   "report_style_numbering": false,
   "user_envs_cfg": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
